#include "settingsdlg.h"
-SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) {
+SettingsDlg::SettingsDlg(QWidget *parent)
+ : QDialog(parent),
+ _currentPage(0)
+{
ui.setupUi(this);
- _currentPage = 0;
-
- //recommendedSize = layout()->minimumSize();
-
- // make the scrollarea behave sanely
- ui.settingsFrame->setWidgetResizable(true);
- ui.settingsFrame->setWidget(ui.settingsStack);
updateGeometry();
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
}
-/*
-QSize SettingsDlg::sizeHint() const {
- return recommendedSize;
-}
-*/
-
-SettingsPage *SettingsDlg::currentPage() const {
- return _currentPage;
-}
-
void SettingsDlg::registerSettingsPage(SettingsPage *sp) {
sp->setParent(ui.settingsStack);
ui.settingsStack->addWidget(sp);
- //recommendedSize = recommendedSize.expandedTo(sp->sizeHint());
- //updateGeometry();
+
connect(sp, SIGNAL(changed(bool)), this, SLOT(setButtonStates()));
QTreeWidgetItem *cat;
cat = new QTreeWidgetItem(ui.settingsTree, QStringList(sp->category()));
cat->setExpanded(true);
cat->setFlags(Qt::ItemIsEnabled);
- } else cat = cats[0];
+ } else {
+ cat = cats[0];
+ }
QTreeWidgetItem *item = new QTreeWidgetItem(cat, QStringList(sp->title()));
- treeItems[sp] = item;
- pages[QString("%1$%2").arg(sp->category(), sp->title())] = sp;
+ item->setData(0, SettingsPageRole, qVariantFromValue<QObject *>(sp));
pageIsLoaded[sp] = false;
- // TESTING
- // selectPage(sp->category(), sp->title());
}
-void SettingsDlg::selectPage(const QString &cat, const QString &title) {
- SettingsPage *sp = pages[QString("%1$%2").arg(cat, title)];
+void SettingsDlg::selectPage(SettingsPage *sp) {
if(!sp) {
_currentPage = 0;
ui.settingsStack->setCurrentIndex(0);
- ui.settingsTree->setCurrentItem(0);
+ ui.pageTitle->setText(tr("Settings"));
return;
}
+
if(!pageIsLoaded[sp]) {
sp->load();
pageIsLoaded[sp] = true;
}
+
if(sp != currentPage() && currentPage() != 0 && currentPage()->hasChanged()) {
int ret = QMessageBox::warning(this, tr("Save changes"),
tr("There are unsaved changes on the current configuration page. Would you like to apply your changes now?"),
undoChanges();
} else sp = currentPage();
}
+
if(sp != currentPage()) {
ui.pageTitle->setText(sp->title());
ui.settingsStack->setCurrentWidget(sp);
- ui.settingsStack->setMinimumSize(sp->minimumSizeHint()); // we don't want our page shrinked, use scrollbars instead...
_currentPage = sp;
}
- ui.settingsTree->setCurrentItem(treeItems[sp]);
setButtonStates();
}
void SettingsDlg::itemSelected() {
QList<QTreeWidgetItem *> items = ui.settingsTree->selectedItems();
- if(!items.count()) {
- return;
- } else {
- QTreeWidgetItem *parent = items[0]->parent();
- if(!parent) return;
- QString cat = parent->text(0);
- QString title = items[0]->text(0);
- selectPage(cat, title);
+ SettingsPage *sp = 0;
+ if(!items.isEmpty()) {
+ sp = qobject_cast<SettingsPage *>(items[0]->data(0, SettingsPageRole).value<QObject *>());
}
+ selectPage(sp);
}
void SettingsDlg::setButtonStates() {
class SettingsDlg : public QDialog {
Q_OBJECT
- public:
- SettingsDlg(QWidget *parent = 0);
- void registerSettingsPage(SettingsPage *);
- void unregisterSettingsPage(SettingsPage *);
- SettingsPage *currentPage() const;
-
- //QSize sizeHint() const;
-
- public slots:
- void selectPage(const QString &category, const QString &title);
-
- private slots:
- void itemSelected();
- void buttonClicked(QAbstractButton *);
- bool applyChanges();
- void undoChanges();
- void reload();
- void loadDefaults();
- void setButtonStates();
-
- private:
- Ui::SettingsDlg ui;
-
- SettingsPage *_currentPage;
- QHash<QString, SettingsPage *> pages;
- QHash<SettingsPage *, QTreeWidgetItem *> treeItems;
- QHash<SettingsPage *, bool> pageIsLoaded;
-
- //QSize recommendedSize;
+public:
+ SettingsDlg(QWidget *parent = 0);
+ void registerSettingsPage(SettingsPage *);
+ void unregisterSettingsPage(SettingsPage *);
+
+ inline SettingsPage *currentPage() const { return _currentPage; }
+
+public slots:
+ void selectPage(SettingsPage *sp); // const QString &category, const QString &title);
+
+private slots:
+ void itemSelected();
+ void buttonClicked(QAbstractButton *);
+ bool applyChanges();
+ void undoChanges();
+ void reload();
+ void loadDefaults();
+ void setButtonStates();
+
+private:
+ Ui::SettingsDlg ui;
+
+ SettingsPage *_currentPage;
+ QHash<SettingsPage *, bool> pageIsLoaded;
+
+ enum {
+ SettingsPageRole = Qt::UserRole
+ };
};
<rect>
<x>0</x>
<y>0</y>
- <width>828</width>
- <height>587</height>
+ <width>725</width>
+ <height>575</height>
</rect>
</property>
<property name="windowTitle" >
<string>Configure Quassel</string>
</property>
- <layout class="QVBoxLayout" >
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
- <layout class="QVBoxLayout" >
- <item>
- <widget class="QSplitter" name="splitter" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QTreeWidget" name="settingsTree" >
+ <property name="maximumSize" >
+ <size>
+ <width>200</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <column>
+ <property name="text" >
+ <string>Settings</string>
</property>
- <widget class="QTreeWidget" name="settingsTree" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="maximumSize" >
- <size>
- <width>200</width>
- <height>16777215</height>
- </size>
- </property>
- <column>
+ </column>
+ </widget>
+ <widget class="QWidget" name="" >
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QLabel" name="pageTitle" >
+ <property name="font" >
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
<property name="text" >
<string>Settings</string>
</property>
- </column>
- </widget>
- <widget class="QWidget" name="layoutWidget" >
- <layout class="QVBoxLayout" >
- <item>
- <widget class="QLabel" name="pageTitle" >
- <property name="font" >
- <font>
- <weight>75</weight>
- <bold>true</bold>
- </font>
- </property>
- <property name="text" >
- <string>Settings</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="Line" name="line" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QScrollArea" name="settingsFrame" >
- <property name="frameShape" >
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow" >
- <enum>QFrame::Sunken</enum>
- </property>
- <layout class="QVBoxLayout" >
- <item>
- <widget class="QStackedWidget" name="settingsStack" >
- <property name="minimumSize" >
- <size>
- <width>16</width>
- <height>16</height>
- </size>
- </property>
- <property name="currentIndex" >
- <number>0</number>
- </property>
- <widget class="QWidget" name="page_3" />
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- </widget>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons" >
- <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set>
- </property>
- </widget>
- </item>
- </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="Line" name="line" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QStackedWidget" name="settingsStack" >
+ <widget class="QWidget" name="page" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>492</width>
+ <height>466</height>
+ </rect>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set>
+ </property>
+ </widget>
</item>
</layout>
</widget>
- <customwidgets>
- <customwidget>
- <class>QScrollArea</class>
- <extends>QFrame</extends>
- <header>QScrollArea</header>
- <container>1</container>
- </customwidget>
- </customwidgets>
<resources/>
<connections/>
</ui>