|
| 1 | +#include <QtCore/QVariant> |
| 2 | +#include <QtWidgets/QApplication> |
| 3 | +#include <QtWidgets/QDialog> |
| 4 | +#include <QtWidgets/QDialogButtonBox> |
| 5 | +#include <QtWidgets/QHBoxLayout> |
| 6 | +#include <QtWidgets/QListWidget> |
| 7 | +#include <QtWidgets/QStackedWidget> |
| 8 | +#include <QtWidgets/QVBoxLayout> |
| 9 | +#include <QtWidgets/QWidget> |
| 10 | +#include <language.h> |
| 11 | +#include <mouse.h> |
| 12 | +#include "appearance.h" |
| 13 | +#include "behaviour.h" |
| 14 | + |
1 | 15 | #include <QDebug> |
2 | 16 | #include <QDir> |
3 | 17 | #include <QFile> |
|
11 | 25 | #include "log.h" |
12 | 26 | #include "macros.h" |
13 | 27 | #include "maindialog.h" |
14 | | -#include "./ui_maindialog.h" |
15 | 28 | #include "xml.h" |
16 | 29 |
|
17 | | -MainDialog::MainDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MainDialog) |
| 30 | +MainDialog::MainDialog(QWidget *parent) : QDialog(parent) |
18 | 31 | { |
19 | | - ui->setupUi(this); |
20 | | - ui->list->setFixedWidth(ui->list->sizeHintForColumn(0) + 2 * ui->list->frameWidth()); |
21 | | - QObject::connect(ui->buttonBox, &QDialogButtonBox::clicked, [&](QAbstractButton *button) { |
22 | | - if (ui->buttonBox->standardButton(button) == QDialogButtonBox::Apply) { |
| 32 | + resize(640, 480); |
| 33 | + |
| 34 | + QVBoxLayout *verticalLayout = new QVBoxLayout(this); |
| 35 | + verticalLayout->setContentsMargins(6, 6, 6, 6); |
| 36 | + |
| 37 | + QWidget *widget = new QWidget(this); |
| 38 | + |
| 39 | + QHBoxLayout *horizontalLayout = new QHBoxLayout(widget); |
| 40 | + horizontalLayout->setContentsMargins(6, 6, 6, 6); |
| 41 | + |
| 42 | + // List Widget on the Left |
| 43 | + QListWidget *list = new QListWidget(widget); |
| 44 | + |
| 45 | + QListWidgetItem *item0 = new QListWidgetItem(list); |
| 46 | + item0->setIcon(QIcon::fromTheme("applications-graphics")); |
| 47 | + item0->setText(tr("Appearance")); |
| 48 | + |
| 49 | + QListWidgetItem *item1 = new QListWidgetItem(list); |
| 50 | + item1->setIcon(QIcon::fromTheme("preferences-desktop")); |
| 51 | + item1->setText(tr("Behaviour")); |
| 52 | + |
| 53 | + QListWidgetItem *item2 = new QListWidgetItem(list); |
| 54 | + item2->setIcon(QIcon::fromTheme("input-mouse")); |
| 55 | + item2->setText(tr("Mouse & Touchpad")); |
| 56 | + |
| 57 | + QListWidgetItem *item3 = new QListWidgetItem(list); |
| 58 | + item3->setIcon(QIcon::fromTheme("preferences-desktop-locale")); |
| 59 | + item3->setText(tr("Language & Region")); |
| 60 | + |
| 61 | + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
| 62 | + sizePolicy.setHorizontalStretch(0); |
| 63 | + sizePolicy.setVerticalStretch(0); |
| 64 | + sizePolicy.setHeightForWidth(list->sizePolicy().hasHeightForWidth()); |
| 65 | + list->setSizePolicy(sizePolicy); |
| 66 | + list->setSizeAdjustPolicy(QAbstractScrollArea::SizeAdjustPolicy::AdjustToContents); |
| 67 | + list->setCurrentRow(0); |
| 68 | + list->setFixedWidth(list->sizeHintForColumn(0) + 2 * list->frameWidth()); |
| 69 | + |
| 70 | + horizontalLayout->addWidget(list); |
| 71 | + |
| 72 | + // The stack containing all the pages |
| 73 | + QStackedWidget *stack = new QStackedWidget(widget); |
| 74 | + |
| 75 | + m_pageAppearance = new Appearance(); |
| 76 | + stack->addWidget(m_pageAppearance); |
| 77 | + |
| 78 | + m_pageBehaviour = new Behaviour(); |
| 79 | + stack->addWidget(m_pageBehaviour); |
| 80 | + |
| 81 | + m_pageMouse = new Mouse(); |
| 82 | + stack->addWidget(m_pageMouse); |
| 83 | + |
| 84 | + m_pageLanguage = new Language(); |
| 85 | + stack->addWidget(m_pageLanguage); |
| 86 | + |
| 87 | + horizontalLayout->addWidget(stack); |
| 88 | + |
| 89 | + verticalLayout->addWidget(widget); |
| 90 | + |
| 91 | + m_buttonBox = new QDialogButtonBox(this); |
| 92 | + m_buttonBox->setOrientation(Qt::Orientation::Horizontal); |
| 93 | + m_buttonBox->setStandardButtons(QDialogButtonBox::StandardButton::Apply |
| 94 | + | QDialogButtonBox::StandardButton::Close); |
| 95 | + m_buttonBox->setCenterButtons(false); |
| 96 | + |
| 97 | + verticalLayout->addWidget(m_buttonBox); |
| 98 | + |
| 99 | + // Change pages when list items are clicked |
| 100 | + QObject::connect(list, SIGNAL(currentRowChanged(int)), stack, SLOT(setCurrentIndex(int))); |
| 101 | + |
| 102 | + // Close Button |
| 103 | + QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
| 104 | + |
| 105 | + // Apply Button |
| 106 | + QObject::connect(m_buttonBox, &QDialogButtonBox::clicked, [&](QAbstractButton *button) { |
| 107 | + if (m_buttonBox->standardButton(button) == QDialogButtonBox::Apply) { |
23 | 108 | onApply(); |
24 | 109 | } |
25 | 110 | }); |
| 111 | + |
26 | 112 | activate(); |
27 | 113 | } |
28 | 114 |
|
29 | 115 | MainDialog::~MainDialog() |
30 | 116 | { |
31 | | - delete ui; |
32 | 117 | xml_finish(); |
33 | 118 | } |
34 | 119 |
|
35 | 120 | void MainDialog::activate() |
36 | 121 | { |
37 | | - ui->pageAppearance->activate(); |
38 | | - ui->pageBehaviour->activate(); |
39 | | - ui->pageMouse->activate(); |
40 | | - ui->pageLanguage->activate(); |
| 122 | + m_pageAppearance->activate(); |
| 123 | + m_pageBehaviour->activate(); |
| 124 | + m_pageMouse->activate(); |
| 125 | + m_pageLanguage->activate(); |
41 | 126 | } |
42 | 127 |
|
43 | 128 | void MainDialog::onApply() |
44 | 129 | { |
45 | | - ui->pageAppearance->onApply(); |
46 | | - ui->pageBehaviour->onApply(); |
47 | | - ui->pageMouse->onApply(); |
48 | | - ui->pageLanguage->onApply(); |
| 130 | + m_pageAppearance->onApply(); |
| 131 | + m_pageBehaviour->onApply(); |
| 132 | + m_pageMouse->onApply(); |
| 133 | + m_pageLanguage->onApply(); |
49 | 134 |
|
50 | 135 | // TODO: Get filename in a more consistent way - share common code with main.cpp |
51 | 136 | std::string config_home = std::getenv("HOME") + std::string("/.config/labwc"); |
|
0 commit comments