-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
99 lines (85 loc) · 3.08 KB
/
mainwindow.cpp
File metadata and controls
99 lines (85 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "sheet.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTimer>
#include <QMainWindow>
#include <QResizeEvent>
#include <QPushButton>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setupSheet();
// setup buttons to show the sheet
auto buttonsPanel = new QWidget(this);
auto buttonsLayout = new QHBoxLayout(buttonsPanel);
buttonsLayout->setSpacing(8);
auto showLeftButton = new QPushButton("Show Left Sheet", this);
connect(showLeftButton, &QPushButton::clicked, this, [this] {
this->m_sheet->showSheet(this, Sheet::Side::Left);
});
auto showRightButton = new QPushButton("Show Right Sheet", this);
connect(showRightButton, &QPushButton::clicked, this, [this] {
this->m_sheet->showSheet(this, Sheet::Side::Right);
});
buttonsLayout->addStretch();
buttonsLayout->addWidget(showLeftButton, 0, Qt::AlignCenter);
buttonsLayout->addWidget(showRightButton, 0, Qt::AlignCenter);
buttonsLayout->addStretch();
auto layout = new QVBoxLayout(this->centralWidget());
layout->addStretch();
layout->addWidget(buttonsPanel);
layout->addStretch();
}
/* Sets up the sheet and its content
* the sheet is a sliding sidepanel and the content can be any QWidget
* To close the sheet from your code invoke hideSheet(true);
* To open the sheet from your code invoke showSheet(QWidget *destination, QWidget *content);
*/
void MainWindow::setupSheet() {
// setup the sheet's content
m_sheetContent = new QWidget(this);
auto sheetLayout = new QVBoxLayout(m_sheetContent);
sheetLayout->setContentsMargins(9, 0, 13, 0);
auto header = new QLabel(this);
header->setText(R"(<html>
<h2>About qtsheet</h2>
<p>qtsheet implements the slideing style-sheets for qt.
The code is free and you just copy 2 files into your project to use it.
</p>
<p>Written by Stepan Rutz</p>
)");
header->setWordWrap(true);
auto image = new QLabel(this);
image->setPixmap(QPixmap(":/resources/pexels-goumbik.jpg"));
sheetLayout->addWidget(header);
sheetLayout->addWidget(image);
sheetLayout->addStretch();
// add another close button to the sheet
auto sheetButton = new QPushButton("Close", this);
connect(sheetButton, &QPushButton::clicked, this, [this] {
this->m_sheet->hideSheet();
});
sheetLayout->addWidget(sheetButton, 0, Qt::AlignRight);
// create the sheet panel
m_sheet = new Sheet(m_sheetContent, this);
// set this to true if you want to hide the close button on the top right
if (false) {
sheetLayout->setContentsMargins(9, 9, 9, 0);
m_sheet->setShowTopRightCloseButton(false);
}
}
void MainWindow::resizeEvent(QResizeEvent *event) {
QMainWindow::resizeEvent(event);
/* invoke the layout method on the sheet it you want it
* to adjust its size during resizing of its parent */
m_sheet->layout(false);
}
MainWindow::~MainWindow()
{
delete ui;
}