1 /***************************************************************************
2 * Copyright (C) 2009 by Lassi Väätämöinen *
3 * lassi.vaatamoinen@ixonos.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <QScrollArea>
23 #include <QGridLayout>
24 #include <QTreeWidgetItem>
26 #include <QDialogButtonBox>
27 #include <QAbstractButton>
29 #include "ColumnSelectorDialog.h"
32 ColumnSelectorDialog::ColumnSelectorDialog(QTreeWidget *treewidget, QWidget* parent, Qt::WindowFlags f) :
33 QDialog(parent, f), // Superclass construct
36 treeWidget_(treewidget),
39 QScrollArea *scrollArea = new QScrollArea(this);
40 scrollArea->setWidgetResizable(true);
41 //scrollArea->setProperty("FingerScrollable", false);
42 QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom);
43 grid_ = new QGridLayout;
44 QCheckBox *cbox = NULL;
46 /// @TODO Kineticscrolling (Fingerscrollable does not work in Qt 4.6, only in 4.5)
48 //Specific hildon/Maemo5 code here
51 // Create scrollable checkbox dialog to allow proper viewing on Maemo:
52 verticalBox->addWidget(scrollArea);
53 // A "temporary" widget for containing QScrollArea stuff
54 QWidget* scrollAreaWidgetContents = new QWidget();
55 scrollAreaWidgetContents->setLayout(grid_);
56 scrollArea->setWidget(scrollAreaWidgetContents);
57 setLayout(verticalBox);
59 if (treeWidget_ != NULL) {
60 QTreeWidgetItem *item = treeWidget_->headerItem();
62 for (unsigned i = 0; i < item->columnCount(); ++i) {
63 cbox = new QCheckBox(item->text(i));
64 grid_->addWidget(cbox, i, 0);
65 treeWidget_->isColumnHidden(i) ? cbox->setCheckState(Qt::Unchecked) : cbox->setCheckState(Qt::Checked);
66 checkBoxes_.push_back(cbox);
71 dialogButtons_ = new QDialogButtonBox(this);
72 dialogButtons_->setStandardButtons(QDialogButtonBox::Ok
73 | QDialogButtonBox::Cancel);
75 verticalBox->addWidget(dialogButtons_);
77 connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)),
78 this, SLOT(on_buttonClicked(QAbstractButton*)));
82 ColumnSelectorDialog::~ColumnSelectorDialog()
87 void ColumnSelectorDialog::on_buttonClicked(QAbstractButton *button)
89 switch (dialogButtons_->buttonRole ( button ) ) {
90 case QDialogButtonBox::AcceptRole :
92 done(QDialog::Accepted);
94 case QDialogButtonBox::ApplyRole :
96 done(QDialog::Accepted);
98 case QDialogButtonBox::RejectRole :
99 done(QDialog::Rejected);
107 void ColumnSelectorDialog::ApplySettings()
109 if (treeWidget_ != NULL) {
110 QTreeWidgetItem *item = treeWidget_->headerItem();
111 QCheckBox *cbox = NULL;
113 for (unsigned i = 0; i < checkBoxes_.size(); ++i) {
114 cbox = checkBoxes_.at(i);
115 cbox->isChecked() ? treeWidget_->showColumn(i) : treeWidget_->hideColumn(i);