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 <QAbstractKineticScroller>
34 #include "ColumnSelectorDialog.h"
37 ColumnSelectorDialog::ColumnSelectorDialog(QTreeWidget *treewidget, QWidget* parent, Qt::WindowFlags f) :
38 QDialog(parent, f), // Superclass construct
41 treeWidget_(treewidget),
45 QScrollArea *scrollArea = new QScrollArea(this);
48 /// @todo Kineticscrolling (property "FingerScrollable" does not work in Qt 4.6, only in 4.5)
49 scroller_ = scrollArea->property("kineticScroller").value<QAbstractKineticScroller*>();
52 qFatal("This example only works with QMaemo5Style as the default style for all QAbstractScrollAreas");
55 scrollArea->setWidgetResizable(true);
56 //scrollArea->setProperty("FingerScrollable", false);
57 QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom);
58 grid_ = new QGridLayout;
59 QCheckBox *cbox = NULL;
63 // Create scrollable checkbox dialog to allow proper viewing on Maemo:
64 verticalBox->addWidget(scrollArea);
65 // A "temporary" widget for containing QScrollArea stuff
66 QWidget* scrollAreaWidgetContents = new QWidget();
67 scrollAreaWidgetContents->setLayout(grid_);
68 scrollArea->setWidget(scrollAreaWidgetContents);
69 setLayout(verticalBox);
71 if (treeWidget_ != NULL) {
72 QTreeWidgetItem *item = treeWidget_->headerItem();
74 for (unsigned i = 0; i < item->columnCount(); ++i) {
75 cbox = new QCheckBox(item->text(i));
76 grid_->addWidget(cbox, i, 0);
77 treeWidget_->isColumnHidden(i) ? cbox->setCheckState(Qt::Unchecked) : cbox->setCheckState(Qt::Checked);
78 checkBoxes_.push_back(cbox);
83 dialogButtons_ = new QDialogButtonBox(this);
84 dialogButtons_->setStandardButtons(QDialogButtonBox::Ok
85 | QDialogButtonBox::Cancel);
87 verticalBox->addWidget(dialogButtons_);
89 connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)),
90 this, SLOT(on_buttonClicked(QAbstractButton*)));
94 ColumnSelectorDialog::~ColumnSelectorDialog()
99 void ColumnSelectorDialog::on_buttonClicked(QAbstractButton *button)
101 switch (dialogButtons_->buttonRole ( button ) ) {
102 case QDialogButtonBox::AcceptRole :
104 done(QDialog::Accepted);
106 case QDialogButtonBox::ApplyRole :
108 done(QDialog::Accepted);
110 case QDialogButtonBox::RejectRole :
111 done(QDialog::Rejected);
119 void ColumnSelectorDialog::ApplySettings()
121 if (treeWidget_ != NULL) {
122 QTreeWidgetItem *item = treeWidget_->headerItem();
123 QCheckBox *cbox = NULL;
125 for (unsigned i = 0; i < checkBoxes_.size(); ++i) {
126 cbox = checkBoxes_.at(i);
127 cbox->isChecked() ? treeWidget_->showColumn(i) : treeWidget_->hideColumn(i);