Skip to content

Commit d6baa2c

Browse files
committed
Switched from QWidget to QDialog
1 parent 256b73d commit d6baa2c

File tree

7 files changed

+64
-42
lines changed

7 files changed

+64
-42
lines changed

app/window.cpp renamed to app/QCpdWindow.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
#include "window.h"
1+
#include "QCpdWindow.h"
2+
#include <QGridLayout>
3+
#include <QQuickItem>
24

3-
_Window *_window;
5+
extern "C" {
6+
#include "../backends/cups/src/CPD.h"
7+
#include "../backends/cups/src/print_frontend.h"
8+
}
9+
static int add_printer_callback(PrinterObj *p);
10+
static int remove_printer_callback(char *printer_name);
11+
void ui_add_printer_aux(gpointer key, gpointer value, gpointer user_data);
12+
13+
QCpdWindow *_window;
414

5-
_Window::_Window(QPrinter *printer, QWidget *parent) :
6-
QWidget(parent),
15+
QCpdWindow::QCpdWindow(QPrinter *printer, QWidget *parent) :
16+
QDialog(parent),
717
masterLayout(new QGridLayout(this)),
818
tabs(new Tabs(this)),
919
root(new Root(this)),
@@ -80,20 +90,20 @@ _Window::_Window(QPrinter *printer, QWidget *parent) :
8090
CPrintDialog::CPrintDialog(QPrinter* printer, QWidget *parent) :
8191
QAbstractPrintDialog(printer, parent)
8292
{
83-
_window = new _Window(printer, parent);
93+
_window = new QCpdWindow(printer, parent);
8494
_window->show();
8595
}
8696

87-
void _Window::tabBarIndexChanged(qint32 index) {
97+
void QCpdWindow::tabBarIndexChanged(qint32 index) {
8898
root->rootObject->setProperty("index", index);
8999
}
90100

91-
void _Window::swipeViewIndexChanged(qint32 index) {
101+
void QCpdWindow::swipeViewIndexChanged(qint32 index) {
92102
tabs->rootObject->setProperty("index", index);
93103
}
94104

95-
void _Window::cancelButtonClicked() {
96-
exit(0);
105+
void QCpdWindow::cancelButtonClicked() {
106+
close();
97107
}
98108

99109
static int add_printer_callback(PrinterObj *p) {
@@ -104,7 +114,7 @@ static int remove_printer_callback(char *printer_name) {
104114
printf("print_frontend.c : Printer %s removed!\n", printer_name);
105115
}
106116

107-
gpointer _Window::ui_add_printer(gpointer user_data) {
117+
gpointer QCpdWindow::ui_add_printer(gpointer user_data) {
108118
/*
109119
* Need this delay so that the FrontendObj
110120
* initialization completes
@@ -129,7 +139,7 @@ void ui_add_printer_aux(gpointer key, gpointer value, gpointer user_data) {
129139
qDebug() << "Added" << (const char*)key;
130140
}
131141

132-
void _Window::addPrinter(const char *printer) {
142+
void QCpdWindow::addPrinter(const char *printer) {
133143
QObject* obj = root->rootObject->findChild<QObject*>("generalObject");
134144
if (obj) {
135145
QMetaObject::invokeMethod(obj,
@@ -140,7 +150,7 @@ void _Window::addPrinter(const char *printer) {
140150
qDebug() << "generalObject Not Found";
141151
}
142152

143-
gpointer _Window::parse_commands(gpointer user_data) {
153+
gpointer QCpdWindow::parse_commands(gpointer user_data) {
144154
Command* cmd = (Command*)user_data;
145155
if (cmd->command.compare("hide-remote-cups") == 0)
146156
hide_remote_cups_printers(f);
@@ -153,7 +163,7 @@ gpointer _Window::parse_commands(gpointer user_data) {
153163
}
154164
}
155165

156-
void _Window::init_backend() {
166+
void QCpdWindow::init_backend() {
157167
event_callback add_cb = (event_callback)add_printer_callback;
158168
event_callback rem_cb = (event_callback)remove_printer_callback;
159169
f = get_new_FrontendObj(NULL, add_cb, rem_cb);
@@ -165,7 +175,7 @@ void _Window::init_backend() {
165175
//g_main_loop_run(loop);
166176
}
167177

168-
void _Window::clearPrinters() {
178+
void QCpdWindow::clearPrinters() {
169179
// QObject* obj = root->rootObject->findChild<QObject*>("generalObject");
170180
// if (obj) {
171181
// QMetaObject::invokeMethod(obj,

app/window.h renamed to app/QCpdWindow.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
#ifndef WINDOW_H
2-
#define WINDOW_H
1+
#ifndef QCPDWINDOW_H
2+
#define QCPDWINDOW_H
33

4-
#include <QGridLayout>
5-
#include <QPainter>
64
#include <QAbstractPrintDialog>
7-
#include <QPrinter>
5+
#include <QDialog>
86
#include "components.h"
97

10-
#include <QDebug>
11-
12-
extern "C" {
13-
#include "../backends/cups/src/CPD.h"
14-
#include "../backends/cups/src/print_frontend.h"
15-
}
168

179
class QPrinter;
10+
class QGridLayout;
11+
12+
struct _FrontendObj;
13+
using FrontendObj = _FrontendObj;
14+
15+
struct _GMainLoop;
16+
using GMainLoop = _GMainLoop;
17+
18+
struct _PrinterObj;
19+
using PrinterObj = _PrinterObj;
1820

19-
static int add_printer_callback(PrinterObj *p);
20-
static int remove_printer_callback(char *printer_name);
21-
void ui_add_printer_aux(gpointer key, gpointer value, gpointer user_data);
21+
using gpointer = void *;
2222

2323
typedef struct {
2424
std::string command;
2525
std::string arg1;
2626
std::string arg2;
2727
} Command;
2828

29-
class _Window : public QWidget {
29+
class QCpdWindow : public QDialog {
3030
Q_OBJECT
3131
public:
3232
FrontendObj *f;
@@ -37,7 +37,7 @@ class _Window : public QWidget {
3737
Controls *controls;
3838
QGridLayout *masterLayout;
3939

40-
_Window(QPrinter* printer, QWidget* parent = Q_NULLPTR);
40+
QCpdWindow(QPrinter* printer, QWidget* parent = Q_NULLPTR);
4141
void init_backend();
4242
void addPrinter(const char* printer);
4343
void clearPrinters();
@@ -62,4 +62,4 @@ class Q_PRINTSUPPORT_EXPORT CPrintDialog : public QAbstractPrintDialog {
6262
int exec() override {}
6363
};
6464

65-
#endif // WINDOW_H
65+
#endif // QCPDWINDOW_H

app/components.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#include "components.h"
2+
#include <QWidget>
3+
#include <QPainter>
4+
#include <QPrinter>
5+
#include <QPrintPreviewWidget>
6+
#include <QQuickWidget>
27
#include <poppler/qt5/poppler-qt5.h>
38

49
Tabs::Tabs(QWidget* parent) :

app/components.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#ifndef COMPONENTS_H
22
#define COMPONENTS_H
33

4-
#include <QQuickItem>
5-
#include <QQuickWidget>
6-
#include <QPrintPreviewWidget>
7-
#include <QPainter>
8-
#include <QPrinter>
4+
#include <QWidget>
5+
6+
class QPrinter;
7+
class QPrintPreviewWidget;
8+
class QQuickItem;
9+
class QQuickWidget;
910

1011
class Tabs : public QWidget {
1112
Q_OBJECT

common-print-dialog.pro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ SOURCES += \#app/main.cpp \
2020
backends/cups/src/frontend_helper.c \
2121
backends/cups/src/common_helper.c \
2222
backends/cups/src/backend_interface.c \
23-
app/window.cpp \
2423
cpd.cpp \
25-
app/components.cpp
24+
app/components.cpp \
25+
app/QCpdWindow.cpp
2626

2727
RESOURCES += qml.qrc
2828

@@ -62,7 +62,7 @@ HEADERS += \
6262
backends/cups/src/CPD.h \
6363
backends/cups/src/common_helper.h \
6464
backends/cups/src/backend_interface.h \
65-
app/window.h \
6665
cpd.h \
6766
cpd_global.h \
68-
app/components.h
67+
app/components.h \
68+
app/QCpdWindow.h

cpd.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "cpd.h"
2-
#include "app/window.h"
2+
#include "app/QCpdWindow.h"
33

44
CPD::CPD(QPrinter *printer, QWidget *parent) :
55
QWidget(parent)
@@ -11,6 +11,11 @@ void CPD::showDialog() {
1111
w->show();
1212
}
1313

14+
15+
int CPD::exec() {
16+
return w->exec();
17+
}
18+
1419
QString CPD::information() {
1520
return QString("CPD Library");
1621
}

cpd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#define CPD_H
33

44
#include "cpd_global.h"
5-
#include <QPrinter>
65
#include <QWidget>
76

7+
class QPrinter;
88
class CPrintDialog;
99

1010
class CPDSHARED_EXPORT CPD : public QWidget
@@ -15,6 +15,7 @@ class CPDSHARED_EXPORT CPD : public QWidget
1515
CPD(QPrinter *printer, QWidget *parent = Q_NULLPTR);
1616
void showDialog();
1717
QString information();
18+
int exec();
1819
};
1920

2021
#endif // CPD_H

0 commit comments

Comments
 (0)