Skip to content

Commit fb50aab

Browse files
redtidejohanmalm
authored andcommitted
Qt: use QDialog
1 parent d3476f1 commit fb50aab

File tree

8 files changed

+227
-305
lines changed

8 files changed

+227
-305
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
build/
1+
build*/
2+
*.user*

CMakeLists.txt

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
cmake_minimum_required(VERSION 3.5)
2-
3-
project(labwc-tweaks VERSION 0.0 LANGUAGES C CXX)
4-
2+
project(labwc-tweaks
3+
VERSION 0.1.0
4+
LANGUAGES C CXX
5+
)
56
set(CMAKE_AUTOUIC ON)
67
set(CMAKE_AUTOMOC ON)
78
set(CMAKE_AUTORCC ON)
89

10+
set(CMAKE_CXX_EXTENSIONS OFF)
911
set(CMAKE_CXX_STANDARD 17)
1012
set(CMAKE_CXX_STANDARD_REQUIRED ON)
13+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
14+
15+
set(PROJECT_QT_VERSION 6 CACHE STRING "Qt version to use [Default: 6]")
1116

1217
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
1318
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined")
1419

15-
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets)
20+
find_package(QT NAMES Qt${PROJECT_QT_VERSION})
1621
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
1722
find_package(PkgConfig REQUIRED)
1823
pkg_search_module(GLIB REQUIRED glib-2.0)
1924
find_package(LibXml2 REQUIRED)
2025

21-
qt_add_executable(${CMAKE_PROJECT_NAME}
22-
MANUAL_FINALIZATION
26+
set(PROJECT_SOURCES
2327
tweaks-qt/main.cpp
24-
tweaks-qt/mainwindow.cpp
25-
tweaks-qt/mainwindow.h
26-
tweaks-qt/mainwindow.ui
28+
tweaks-qt/maindialog.ui
29+
tweaks-qt/maindialog.cpp
30+
tweaks-qt/maindialog.h
2731
environment.c
2832
environment.h
2933
theme.c
@@ -33,21 +37,25 @@ qt_add_executable(${CMAKE_PROJECT_NAME}
3337
keyboard-layouts.c
3438
keyboard-layouts.h
3539
)
40+
source_group("" FILES ${PROJECT_SOURCES})
3641

37-
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE .)
38-
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${GLIB_INCLUDE_DIRS})
39-
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${LIBXML2_INCLUDE_DIR})
40-
41-
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt6::Widgets ${GLIB_LDFLAGS} ${LIBXML2_LIBRARIES})
42-
target_link_libraries(${CMAKE_PROJECT_NAME} INTERFACE ${GLIB_LDFLAGS})
42+
qt_add_executable(${PROJECT_NAME} MANUAL_FINALIZATION
43+
${PROJECT_SOURCES}
44+
)
45+
target_include_directories(${PROJECT_NAME} PRIVATE ${GLIB_INCLUDE_DIRS})
46+
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBXML2_INCLUDE_DIR})
4347

44-
#target_link_options(${CMAKE_PROJECT_NAME} BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address)
48+
target_link_libraries(${PROJECT_NAME} PRIVATE
49+
Qt${QT_VERSION_MAJOR}::Widgets
50+
${GLIB_LDFLAGS}
51+
${LIBXML2_LIBRARIES}
52+
)
53+
#target_link_options(${PROJECT_NAME} BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address)
4554

4655
include(GNUInstallDirs)
47-
install(TARGETS ${CMAKE_PROJECT_NAME}
56+
install(TARGETS ${PROJECT_NAME}
4857
BUNDLE DESTINATION .
4958
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
5059
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
5160
)
52-
53-
qt_finalize_executable(${CMAKE_PROJECT_NAME})
61+
qt_finalize_executable(${PROJECT_NAME})

tweaks-qt/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#include "mainwindow.h"
1+
#include "maindialog.h"
22

33
#include <QApplication>
44

55
int main(int argc, char *argv[])
66
{
77
QApplication a(argc, argv);
8-
MainWindow w;
8+
MainDialog w;
99
w.show();
1010
return a.exec();
1111
}

tweaks-qt/mainwindow.cpp renamed to tweaks-qt/maindialog.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <glib.h>
33
#include <string>
44
#include <unistd.h>
5-
#include "mainwindow.h"
6-
#include "./ui_mainwindow.h"
5+
#include "maindialog.h"
6+
#include "./ui_maindialog.h"
77

88
extern "C" {
99
#include "environment.h"
@@ -12,7 +12,9 @@ extern "C" {
1212
#include "xml.h"
1313
}
1414

15-
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
15+
MainDialog::MainDialog(QWidget *parent)
16+
: QDialog(parent)
17+
, ui(new Ui::MainDialog)
1618
{
1719
ui->setupUi(this);
1820

@@ -21,13 +23,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
2123
xml_init(config_file.data());
2224
xml_setup_nodes();
2325

24-
QObject::connect(ui->quit, &QPushButton::clicked, this, &MainWindow::quitSlot);
25-
QObject::connect(ui->update, &QPushButton::clicked, this, &MainWindow::updateSlot);
26+
QObject::connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &MainDialog::onApply);
2627

2728
activate();
2829
}
2930

30-
MainWindow::~MainWindow()
31+
MainDialog::~MainDialog()
3132
{
3233
delete ui;
3334
xml_finish();
@@ -42,7 +43,7 @@ static const char *first_field(char *s, char delim)
4243
return s;
4344
}
4445

45-
void MainWindow::activate()
46+
void MainDialog::activate()
4647
{
4748
/* # APPEARANCE */
4849

@@ -122,12 +123,7 @@ void MainWindow::activate()
122123
keyboard_layouts_finish(keyboard_layouts);
123124
}
124125

125-
void MainWindow::quitSlot(void)
126-
{
127-
this->close();
128-
}
129-
130-
void MainWindow::updateSlot(void)
126+
void MainDialog::onApply()
131127
{
132128
/* ~/.config/labwc/rc.xml */
133129
xml_set_num((char *)"/labwc_config/theme/cornerradius", ui->cornerRadius->value());

tweaks-qt/maindialog.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef MAINDIALOG_H
2+
#define MAINDIALOG_H
3+
4+
#include <QDialog>
5+
6+
QT_BEGIN_NAMESPACE
7+
namespace Ui {
8+
class MainDialog;
9+
}
10+
QT_END_NAMESPACE
11+
12+
class MainDialog : public QDialog
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
MainDialog(QWidget *parent = nullptr);
18+
~MainDialog();
19+
void activate();
20+
21+
private:
22+
void onApply();
23+
24+
Ui::MainDialog *ui;
25+
};
26+
#endif // MAINDIALOG_H

tweaks-qt/maindialog.ui

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainDialog</class>
4+
<widget class="QDialog" name="MainDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>658</width>
10+
<height>535</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<widget class="QTabWidget" name="tabWidget">
19+
<property name="minimumSize">
20+
<size>
21+
<width>640</width>
22+
<height>480</height>
23+
</size>
24+
</property>
25+
<property name="currentIndex">
26+
<number>0</number>
27+
</property>
28+
<widget class="QWidget" name="tab">
29+
<attribute name="title">
30+
<string>Appearance</string>
31+
</attribute>
32+
<layout class="QFormLayout" name="formLayout">
33+
<item row="1" column="0">
34+
<widget class="QLabel" name="label_2">
35+
<property name="text">
36+
<string>Corner Radius</string>
37+
</property>
38+
</widget>
39+
</item>
40+
<item row="0" column="0">
41+
<widget class="QLabel" name="label">
42+
<property name="text">
43+
<string>Openbox Theme</string>
44+
</property>
45+
</widget>
46+
</item>
47+
<item row="0" column="1">
48+
<widget class="QComboBox" name="openboxTheme"/>
49+
</item>
50+
<item row="1" column="1">
51+
<widget class="QSpinBox" name="cornerRadius"/>
52+
</item>
53+
</layout>
54+
</widget>
55+
<widget class="QWidget" name="tab_2">
56+
<attribute name="title">
57+
<string>Mouse &amp;&amp; Touchpad</string>
58+
</attribute>
59+
<layout class="QFormLayout" name="formLayout_2">
60+
<item row="0" column="0">
61+
<widget class="QLabel" name="label_3">
62+
<property name="text">
63+
<string>Cursor Theme</string>
64+
</property>
65+
</widget>
66+
</item>
67+
<item row="0" column="1">
68+
<widget class="QComboBox" name="cursorTheme"/>
69+
</item>
70+
<item row="1" column="0">
71+
<widget class="QLabel" name="label_4">
72+
<property name="text">
73+
<string>Cursor Size</string>
74+
</property>
75+
</widget>
76+
</item>
77+
<item row="1" column="1">
78+
<widget class="QSpinBox" name="cursorSize"/>
79+
</item>
80+
<item row="2" column="0">
81+
<widget class="QLabel" name="label_5">
82+
<property name="text">
83+
<string>Natural Scroll</string>
84+
</property>
85+
</widget>
86+
</item>
87+
<item row="2" column="1">
88+
<widget class="QComboBox" name="naturalScroll"/>
89+
</item>
90+
</layout>
91+
</widget>
92+
<widget class="QWidget" name="tab_3">
93+
<attribute name="title">
94+
<string>Language &amp;&amp; Region</string>
95+
</attribute>
96+
<layout class="QFormLayout" name="formLayout_3">
97+
<item row="0" column="0">
98+
<widget class="QLabel" name="label_6">
99+
<property name="text">
100+
<string>Keyboard Layout</string>
101+
</property>
102+
</widget>
103+
</item>
104+
<item row="0" column="1">
105+
<widget class="QComboBox" name="keyboardLayout"/>
106+
</item>
107+
</layout>
108+
</widget>
109+
</widget>
110+
</item>
111+
<item>
112+
<widget class="QDialogButtonBox" name="buttonBox">
113+
<property name="orientation">
114+
<enum>Qt::Horizontal</enum>
115+
</property>
116+
<property name="standardButtons">
117+
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set>
118+
</property>
119+
<property name="centerButtons">
120+
<bool>false</bool>
121+
</property>
122+
</widget>
123+
</item>
124+
</layout>
125+
</widget>
126+
<resources/>
127+
<connections>
128+
<connection>
129+
<sender>buttonBox</sender>
130+
<signal>accepted()</signal>
131+
<receiver>MainDialog</receiver>
132+
<slot>accept()</slot>
133+
<hints>
134+
<hint type="sourcelabel">
135+
<x>248</x>
136+
<y>254</y>
137+
</hint>
138+
<hint type="destinationlabel">
139+
<x>157</x>
140+
<y>274</y>
141+
</hint>
142+
</hints>
143+
</connection>
144+
<connection>
145+
<sender>buttonBox</sender>
146+
<signal>rejected()</signal>
147+
<receiver>MainDialog</receiver>
148+
<slot>reject()</slot>
149+
<hints>
150+
<hint type="sourcelabel">
151+
<x>316</x>
152+
<y>260</y>
153+
</hint>
154+
<hint type="destinationlabel">
155+
<x>286</x>
156+
<y>274</y>
157+
</hint>
158+
</hints>
159+
</connection>
160+
</connections>
161+
</ui>

tweaks-qt/mainwindow.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)