summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-09-17 17:16:40 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-30 10:36:49 -0700
commitb7a476169d50dbf4d40b134faac5b88cabd4fa17 (patch)
treea5ee185f0b9683f5d4e8f8144bb5079c18598bb7 /desktop-widgets
parent255325e219f7d1922ac7740649fdbc89228a36c1 (diff)
downloadsubsurface-b7a476169d50dbf4d40b134faac5b88cabd4fa17.tar.gz
Preferecnes: add the initial skeleton
This Preferences dialog should be visually similar to the old one - the main difference is how it acts on the preferences. It's also not based on .ui files since it's a very simple widget I prefered to mount it by hand - no more than 6 lines of c++ code. Right now we have only one preference page on this, and nothing is hoocked up. I've also changed mainwindow a bit to only show this dialog for testing purposes. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/CMakeLists.txt2
-rw-r--r--desktop-widgets/mainwindow.cpp3
-rw-r--r--desktop-widgets/preferences/CMakeLists.txt1
-rw-r--r--desktop-widgets/preferences/preferencesdialog.cpp83
-rw-r--r--desktop-widgets/preferences/preferencesdialog.h30
5 files changed, 118 insertions, 1 deletions
diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt
index 6d9051b10..7b3e60f3b 100644
--- a/desktop-widgets/CMakeLists.txt
+++ b/desktop-widgets/CMakeLists.txt
@@ -91,4 +91,4 @@ target_link_libraries(subsurface_statistics ${QT_LIBRARIES})
add_library(subsurface_generated_ui STATIC ${SUBSURFACE_UI_HDRS})
target_link_libraries(subsurface_generated_ui ${QT_LIBRARIES})
add_library(subsurface_interface STATIC ${SUBSURFACE_INTERFACE})
-target_link_libraries(subsurface_interface ${QT_LIBRARIES} ${MARBLE_LIBRARIES})
+target_link_libraries(subsurface_interface ${QT_LIBRARIES} ${MARBLE_LIBRARIES} subsurface_desktop_preferences)
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 43b433d62..156034598 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -40,6 +40,7 @@
#include "divesitehelpers.h"
#include "windowtitleupdate.h"
#include "locationinformation.h"
+#include "preferences/preferencesdialog.h"
#ifndef NO_USERMANUAL
#include "usermanual.h"
@@ -254,6 +255,8 @@ MainWindow::MainWindow() : QMainWindow(),
ui.menubar->show();
set_git_update_cb(&updateProgress);
+ PreferencesDialogV2 *d = new PreferencesDialogV2();
+ d->show();
}
MainWindow::~MainWindow()
diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt
index 6af8b4a73..468501e7d 100644
--- a/desktop-widgets/preferences/CMakeLists.txt
+++ b/desktop-widgets/preferences/CMakeLists.txt
@@ -11,6 +11,7 @@ source_group("Subsurface Interface Files" FILES ${SUBSURFACE_PREFERENCES_UI})
set(SUBSURFACE_PREFERENCES_LIB_SRCS
abstractpreferenceswidget.cpp
+ preferencesdialog.cpp
preferences_language.cpp
)
diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp
new file mode 100644
index 000000000..b2eb77975
--- /dev/null
+++ b/desktop-widgets/preferences/preferencesdialog.cpp
@@ -0,0 +1,83 @@
+#include "preferencesdialog.h"
+
+#include "abstractpreferenceswidget.h"
+#include "preferences_language.h"
+
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QListWidget>
+#include <QStackedWidget>
+#include <QDialogButtonBox>
+
+PreferencesDialogV2::PreferencesDialogV2()
+{
+ pagesList = new QListWidget();
+ pagesStack = new QStackedWidget();
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Apply|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Cancel);
+
+ pagesList->setMinimumWidth(120);
+ pagesList->setMaximumWidth(120);
+
+ QHBoxLayout *h = new QHBoxLayout();
+ h->addWidget(pagesList);
+ h->addWidget(pagesStack);
+
+ QVBoxLayout *v = new QVBoxLayout();
+ v->addLayout(h);
+ v->addWidget(buttonBox);
+
+ setLayout(v);
+
+ addPreferencePage(new PreferencesLanguage());
+ refreshPages();
+ connect(pagesList, &QListWidget::currentRowChanged,
+ pagesStack, &QStackedWidget::setCurrentIndex);
+}
+
+PreferencesDialogV2::~PreferencesDialogV2()
+{
+}
+
+bool abstractpreferenceswidget_lessthan(AbstractPreferencesWidget *p1, AbstractPreferencesWidget *p2)
+{
+ return p1->positionHeight() <= p2->positionHeight();
+}
+
+void PreferencesDialogV2::addPreferencePage(AbstractPreferencesWidget *page)
+{
+ pages.push_back(page);
+ qSort(pages.begin(), pages.end(), abstractpreferenceswidget_lessthan);
+}
+
+void PreferencesDialogV2::refreshPages()
+{
+ // Remove things
+ pagesList->clear();
+ while(pagesStack->count()) {
+ QWidget *curr = pagesStack->widget(0);
+ pagesStack->removeWidget(curr);
+ curr->setParent(0);
+ }
+
+ // Readd things.
+ Q_FOREACH(AbstractPreferencesWidget *page, pages) {
+ QListWidgetItem *item = new QListWidgetItem(page->icon(), page->name());
+ pagesList->addItem(item);
+ pagesStack->addWidget(page);
+ }
+}
+
+void PreferencesDialogV2::applyRequested()
+{
+ //TODO
+}
+
+void PreferencesDialogV2::cancelRequested()
+{
+ //TODO
+}
+
+void PreferencesDialogV2::defaultsRequested()
+{
+ //TODO
+}
diff --git a/desktop-widgets/preferences/preferencesdialog.h b/desktop-widgets/preferences/preferencesdialog.h
new file mode 100644
index 000000000..a1db94b43
--- /dev/null
+++ b/desktop-widgets/preferences/preferencesdialog.h
@@ -0,0 +1,30 @@
+#ifndef PREFERENCES_WIDGET_H
+#define PREFERENCES_WIDGET_H
+
+#include <QDialog>
+#include "pref.h"
+
+class AbstractPreferencesWidget;
+class QListWidget;
+class QStackedWidget;
+class QDialogButtonBox;
+
+class PreferencesDialogV2 : public QDialog {
+ Q_OBJECT
+public:
+ PreferencesDialogV2();
+ virtual ~PreferencesDialogV2();
+ void addPreferencePage(AbstractPreferencesWidget *page);
+ void refreshPages();
+private:
+ void cancelRequested();
+ void applyRequested();
+ void defaultsRequested();
+
+ QList<AbstractPreferencesWidget*> pages;
+ QListWidget *pagesList;
+ QStackedWidget *pagesStack;
+ QDialogButtonBox *buttonBox;
+};
+
+#endif \ No newline at end of file