Astyle kdelibs
[kdepim.git] / kmail / configuredialog / configuredialoglistview.cpp
blob6e7be3cf32f82e928f19acfb6bda3c8f1c2acf61
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 * kmail: KDE mail client
3 */
5 #include "configuredialoglistview.h"
7 #include <KLocalizedString>
8 #include <QMenu>
10 ListView::ListView(QWidget *parent)
11 : QTreeWidget(parent)
13 setAllColumnsShowFocus(true);
14 setAlternatingRowColors(true);
15 setSelectionMode(QAbstractItemView::SingleSelection);
16 setRootIsDecorated(false);
17 setContextMenuPolicy(Qt::CustomContextMenu);
18 connect(this, &ListView::customContextMenuRequested, this, &ListView::slotContextMenu);
21 void ListView::resizeEvent(QResizeEvent *e)
23 QTreeWidget::resizeEvent(e);
24 resizeColums();
27 void ListView::showEvent(QShowEvent *e)
29 QTreeWidget::showEvent(e);
30 resizeColums();
33 void ListView::resizeColums()
35 const int c = columnCount();
36 if (c == 0) {
37 return;
40 const int w1 = viewport()->width();
41 const int w2 = w1 / c;
42 const int w3 = w1 - (c - 1) * w2;
44 for (int i = 0; i < c - 1; ++i) {
45 setColumnWidth(i, w2);
47 setColumnWidth(c - 1, w3);
50 void ListView::slotContextMenu(const QPoint &pos)
52 QMenu *menu = new QMenu(this);
53 menu->addAction(i18n("Add"), this, SIGNAL(addHeader()));
54 if (currentItem()) {
55 menu->addAction(i18n("Remove"), this, SIGNAL(removeHeader()));
57 menu->exec(viewport()->mapToGlobal(pos));
58 delete menu;