1 /***************************************************************************
2 * Copyright (C) 2010 by Ixonos Plc *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; version 2 of the License. *
8 * This program is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11 * GNU General Public License for more details. *
13 * You should have received a copy of the GNU General Public License *
14 * along with this program; if not, write to the *
15 * Free Software Foundation, Inc., *
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17 ***************************************************************************/
20 #include <QScrollArea>
22 #include <QGridLayout>
23 #include <QTreeWidgetItem>
25 #include <QDialogButtonBox>
26 #include <QAbstractButton>
29 #include <QAbstractKineticScroller>
32 #include "ColumnSelectorDialog.h"
35 ColumnSelectorDialog::ColumnSelectorDialog(QTreeWidget *treewidget, QWidget* parent, Qt::WindowFlags f) :
36 QDialog(parent, f), // Superclass construct
39 treeWidget_(treewidget),
43 QScrollArea *scrollArea = new QScrollArea(this);
46 /// @todo Kineticscrolling (property "FingerScrollable" does not work in Qt 4.6, only in 4.5)
47 scroller_ = scrollArea->property("kineticScroller").value<QAbstractKineticScroller*>();
50 qFatal("This example only works with QMaemo5Style as the default style for all QAbstractScrollAreas");
53 scrollArea->setWidgetResizable(true);
54 //scrollArea->setProperty("FingerScrollable", false);
55 QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom);
56 grid_ = new QGridLayout;
57 QCheckBox *cbox = NULL;
61 // Create scrollable checkbox dialog to allow proper viewing on Maemo:
62 verticalBox->addWidget(scrollArea);
63 // A "temporary" widget for containing QScrollArea stuff
64 QWidget* scrollAreaWidgetContents = new QWidget();
65 scrollAreaWidgetContents->setLayout(grid_);
66 scrollArea->setWidget(scrollAreaWidgetContents);
67 setLayout(verticalBox);
69 if (treeWidget_ != NULL) {
70 QTreeWidgetItem *item = treeWidget_->headerItem();
72 for (unsigned i = 0; i < item->columnCount(); ++i) {
73 cbox = new QCheckBox(item->text(i));
74 grid_->addWidget(cbox, i, 0);
75 treeWidget_->isColumnHidden(i) ? cbox->setCheckState(Qt::Unchecked) : cbox->setCheckState(Qt::Checked);
76 checkBoxes_.push_back(cbox);
81 dialogButtons_ = new QDialogButtonBox(this);
82 dialogButtons_->setStandardButtons(QDialogButtonBox::Ok
83 | QDialogButtonBox::Cancel);
85 verticalBox->addWidget(dialogButtons_);
87 connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)),
88 this, SLOT(on_buttonClicked(QAbstractButton*)));
92 ColumnSelectorDialog::~ColumnSelectorDialog()
97 void ColumnSelectorDialog::on_buttonClicked(QAbstractButton *button)
99 switch (dialogButtons_->buttonRole ( button ) ) {
100 case QDialogButtonBox::AcceptRole :
102 done(QDialog::Accepted);
104 case QDialogButtonBox::ApplyRole :
106 done(QDialog::Accepted);
108 case QDialogButtonBox::RejectRole :
109 done(QDialog::Rejected);
117 void ColumnSelectorDialog::ApplySettings()
119 if (treeWidget_ != NULL) {
120 QTreeWidgetItem *item = treeWidget_->headerItem();
121 QCheckBox *cbox = NULL;
123 for (unsigned i = 0; i < checkBoxes_.size(); ++i) {
124 cbox = checkBoxes_.at(i);
125 cbox->isChecked() ? treeWidget_->showColumn(i) : treeWidget_->hideColumn(i);