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 ***************************************************************************/
22 #include <QScrollArea>
24 #include <QGridLayout>
25 #include <QTreeWidgetItem>
27 #include <QDialogButtonBox>
28 #include <QAbstractButton>
31 #include <QtMaemo5/QMaemo5KineticScroller>
34 #include "ColumnSelectorDialog.h"
37 ColumnSelectorDialog::ColumnSelectorDialog(QTreeWidget *treewidget, QWidget* parent, Qt::WindowFlags f) :
38 QDialog(parent, f), // Superclass construct
41 treeWidget_(treewidget),
44 /// @TODO Kineticscrolling (Fingerscrollable does not work in Qt 4.6, only in 4.5)
45 QScrollArea *scrollArea = new QScrollArea(this);
48 new QMaemo5KineticScroller(scrollArea);
51 scrollArea->setWidgetResizable(true);
52 //scrollArea->setProperty("FingerScrollable", false);
53 QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom);
54 grid_ = new QGridLayout;
55 QCheckBox *cbox = NULL;
59 // Create scrollable checkbox dialog to allow proper viewing on Maemo:
60 verticalBox->addWidget(scrollArea);
61 // A "temporary" widget for containing QScrollArea stuff
62 QWidget* scrollAreaWidgetContents = new QWidget();
63 scrollAreaWidgetContents->setLayout(grid_);
64 scrollArea->setWidget(scrollAreaWidgetContents);
65 setLayout(verticalBox);
67 if (treeWidget_ != NULL) {
68 QTreeWidgetItem *item = treeWidget_->headerItem();
70 for (unsigned i = 0; i < item->columnCount(); ++i) {
71 cbox = new QCheckBox(item->text(i));
72 grid_->addWidget(cbox, i, 0);
73 treeWidget_->isColumnHidden(i) ? cbox->setCheckState(Qt::Unchecked) : cbox->setCheckState(Qt::Checked);
74 checkBoxes_.push_back(cbox);
79 dialogButtons_ = new QDialogButtonBox(this);
80 dialogButtons_->setStandardButtons(QDialogButtonBox::Ok
81 | QDialogButtonBox::Cancel);
83 verticalBox->addWidget(dialogButtons_);
85 connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)),
86 this, SLOT(on_buttonClicked(QAbstractButton*)));
90 ColumnSelectorDialog::~ColumnSelectorDialog()
95 void ColumnSelectorDialog::on_buttonClicked(QAbstractButton *button)
97 switch (dialogButtons_->buttonRole ( button ) ) {
98 case QDialogButtonBox::AcceptRole :
100 done(QDialog::Accepted);
102 case QDialogButtonBox::ApplyRole :
104 done(QDialog::Accepted);
106 case QDialogButtonBox::RejectRole :
107 done(QDialog::Rejected);
115 void ColumnSelectorDialog::ApplySettings()
117 if (treeWidget_ != NULL) {
118 QTreeWidgetItem *item = treeWidget_->headerItem();
119 QCheckBox *cbox = NULL;
121 for (unsigned i = 0; i < checkBoxes_.size(); ++i) {
122 cbox = checkBoxes_.at(i);
123 cbox->isChecked() ? treeWidget_->showColumn(i) : treeWidget_->hideColumn(i);