Skip to content

Commit ac50e39

Browse files
Adaptado para superclasse | Adapted to superclass
CustomTitlebar tornou-se uma superclasse. Agora ele está em sua primeira produção. Release: 0.9.1.0 EN CustomTitlebar has become a superclass. And now it is on its first release. Release: 0.9.1.0
1 parent 2cec7c2 commit ac50e39

27 files changed

Lines changed: 1286 additions & 225 deletions

CustomTitlebar.pro

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# Developer: Mauro Mascarenhas de Araújo
55
# Contact: mauro.mascarenhas@nintersoft.com
66
# License: Nintersoft Open Source Code Licence
7-
# Date: 15 of June of 2017
7+
# Date: 31 of May of 2018
8+
# Version: 0.9.1.0
89
#
910
#-------------------------------------------------
1011

@@ -29,13 +30,13 @@ DEFINES += QT_DEPRECATED_WARNINGS
2930

3031
SOURCES += \
3132
main.cpp \
32-
frmmain.cpp \
33-
titlebar.cpp
33+
titlebar.cpp \
34+
nmainwindow.cpp
3435

3536
HEADERS += \
36-
frmmain.h \
37-
titlebar.h
37+
titlebar.h \
38+
nmainwindow.h
3839

3940
FORMS += \
40-
frmmain.ui \
41-
titlebar.ui
41+
titlebar.ui \
42+
nmainwindow.ui

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# CustomTitlebar
2-
CustomTitlebar é um programa base desenvolvido com a biblioteca Qt, no qual é possível basear-se nele a fim de desenvolver outros programas que usarão bordas personalizadas (não geradas pelo SO) - veja as capturas de tela para maiores detalhes.
32

4-
Características:
3+
CustomTitlebar é um projeto cuja classe principal (NMainWindow) deriva da classe QMainWindow da biblioteca Qt.
4+
Ao derivar a janela principal da classe NMainWindow, você poderá desenvolver programas que usarão bordas personalizadas (não geradas pelo SO) - veja as capturas de tela para maiores detalhes.
5+
6+
## Suporte e Documentação
7+
8+
Você poderá obter o suporte e documentação para o uso deste projeto em sua [página no site da Nintersoft](https://www.nintersoft.com/portfolio/custom-titlebar/) ou ainda em sua [página de documentação](https://docwiki.nintersoft.com/custom-titlebar/).
9+
10+
## Características:
511
- Redimensionável (100% funcional)
612
- Botões personalizáveis
713
- Atualização do título da janela (QMainWindow::setWindowTitle(QString)) funcionando;
@@ -24,26 +30,31 @@ Mauro Mascarenhas - Nintersoft.
2430

2531
## EN
2632
# CustomTitlebar
27-
CustomTitlebar is a base program which uses Qt library and can be used to develop other bordeless programs that needs custom borders (the frame is not dynamically generated by the OS), - have a look at the screenshots folder for more details.
2833

29-
Features:
34+
CustomTitlebar is a project where the main class (NMainWindow) inherits its properties from QMainWindow, which is part of Qt Library.
35+
Inheriting the main window from the NMainWindow class, will allow you to develop programs which will use customized borders (not generated by the OS) - have a look at the screenshots for major details.
36+
37+
## Support and Documentation
38+
39+
You are able to get the proper support and documentation in order to use this project on its [page at Nintersoft's website](https://www.nintersoft.com/en/portfolio/custom-titlebar/) or yet on its [documentation page](https://docwiki.nintersoft.com/en/custom-titlebar/).
40+
41+
## Features:
3042
- Resizeable (100% functional)
3143
- BotõesCustomizable buttons
3244
- Window title update (QMainWindow::setWindowTitle(QString)) working properly;
3345

34-
CustomTitlebar open source code
46+
## CustomTitlebar open source code
3547
- You can download and make some modifications in the source code, according to our Open Source Policy (by Nintersoft).
3648
- The licence is available in the root of the project folder.
3749

38-
Once this project is supported by Nintersoft open source licence you either can (checked) or musn't (unchecked):
50+
Once this project is supported by Nintersoft open source code licence you are either allowed to (checked), or musn't (unchecked):
3951
- [x] Download or clone into your repository and make changes.
4052
- [x] Share the improvements you made in the source with the community.
4153
- [ ] Sell parts of the source of this project (even when already compiled).
4254
- [ ] Use your own logo or slogan.
4355
- [x] You must read the rest of the licence in the root of the project folder and know better your rights and obligations.
4456

45-
46-
If you clone this directory into yours, please put a linkback to our webpage and the correct references for out team, also leaving the original README in your repository.
57+
If you clone this directory into yours, please insert a linkback to our webpage and the correct references to our team, also leaving the original README in your repository.
4758

4859
Graciously,
4960
Mauro Mascarenhas - Nintersoft.
8.94 KB
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2018-05-29T00:56:56
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = CustomFrameTestIn
12+
TEMPLATE = app
13+
14+
# The following define makes your compiler emit warnings if you use
15+
# any feature of Qt which has been marked as deprecated (the exact warnings
16+
# depend on your compiler). Please consult the documentation of the
17+
# deprecated API in order to know how to port your code away from it.
18+
DEFINES += QT_DEPRECATED_WARNINGS
19+
20+
# You can also make your code fail to compile if you use deprecated APIs.
21+
# In order to do so, uncomment the following line.
22+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
23+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24+
25+
26+
INCLUDEPATH += ./nmainwindow
27+
28+
SOURCES += \
29+
main.cpp \
30+
nmainwindow/titlebar.cpp \
31+
nmainwindow/nmainwindow.cpp \
32+
testwindow.cpp
33+
34+
HEADERS += \
35+
nmainwindow/titlebar.h \
36+
nmainwindow/nmainwindow.h \
37+
testwindow.h
38+
39+
FORMS += \
40+
nmainwindow/titlebar.ui \
41+
nmainwindow/nmainwindow.ui \
42+
testwindow.ui
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "testwindow.h"
2+
#include <QApplication>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QApplication a(argc, argv);
7+
TestWindow w;
8+
w.show();
9+
10+
return a.exec();
11+
}

frmmain.cpp renamed to Sample Program/CustomFrameTestIn/nmainwindow/nmainwindow.cpp

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
#include "frmmain.h"
2-
#include "ui_frmmain.h"
1+
/*-------------------------------------------------
2+
#
3+
# Project developed by Nintersoft team
4+
# Developer: Mauro Mascarenhas de Araújo
5+
# Contact: mauro.mascarenhas@nintersoft.com
6+
# License: Nintersoft Open Source Code Licence
7+
# Date: 31 of May of 2018
8+
#
9+
------------------------------------------------- */
310

4-
frmMain::frmMain(QWidget *parent) :
11+
#include "nmainwindow.h"
12+
#include "ui_nmainwindow.h"
13+
14+
NMainWindow::NMainWindow(QWidget *parent) :
515
QMainWindow(parent),
6-
ui(new Ui::frmMain)
16+
ui(new Ui::NMainWindow),
17+
RESIZE_LIMIT(2)
718
{
819
ui->setupUi(this);
920
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
@@ -17,37 +28,84 @@ frmMain::frmMain(QWidget *parent) :
1728

1829
setWindowTitle("Custom Window Border");
1930
locked = LockMoveType::None;
31+
32+
ui->headerWidget->setTitleBarWidget(ui->titleBar);
33+
if (ui->titleBar->mainWindow() != this)
34+
ui->titleBar->setMainWindow(this);
35+
36+
if (this->maximumSize() == this->minimumSize())
37+
setMaximizeButtonEnabled(false);
38+
39+
/*
40+
* End of non client area implementation
41+
*/
2042
}
2143

22-
frmMain::~frmMain()
44+
NMainWindow::~NMainWindow()
2345
{
2446
delete ui;
2547
}
2648

27-
void frmMain::mousePressEvent(QMouseEvent *event)
49+
void NMainWindow::setCustomWidgets(QWidget *newCentralWidget, QStatusBar *newStatusBar){
50+
setCustomStatusBar(newStatusBar);
51+
setNewCentralWidget(newCentralWidget);
52+
}
53+
54+
void NMainWindow::setCustomStatusBar(QStatusBar *newStatusBar){
55+
if (!newStatusBar) return;
56+
newStatusBar->installEventFilter(this);
57+
newStatusBar->setMouseTracking(true);
58+
}
59+
60+
void NMainWindow::setNewCentralWidget(QWidget *newCentralWidget){
61+
if (!newCentralWidget) return;
62+
newCentralWidget->installEventFilter(this);
63+
newCentralWidget->setMouseTracking(true);
64+
65+
if (newCentralWidget->layout())
66+
newCentralWidget->layout()->setContentsMargins(10, 0, 10, 0);
67+
}
68+
69+
void NMainWindow::setCloseButtonEnabled(bool enable){
70+
ui->titleBar->setCloseButtonEnabled(enable);
71+
}
72+
73+
void NMainWindow::setMaximizeButtonEnabled(bool enable){
74+
ui->titleBar->setMaximizeButtonEnabled(enable);
75+
}
76+
77+
void NMainWindow::setMinimizeButtonEnabled(bool enable){
78+
ui->titleBar->setMinimizeButtonEnabled(enable);
79+
}
80+
81+
/*
82+
* GUI Functions (do not change them, unless its really necessary)
83+
*/
84+
85+
void NMainWindow::mousePressEvent(QMouseEvent *event)
2886
{
2987
if(event->button() == Qt::LeftButton)
3088
{
31-
int x = event->x(), y = event->y(), bottom = this->height() - 5, right = this->width() - 5;
32-
if (x < 5 && y < 5){
89+
int x = event->x(), y = event->y(), bottom = this->height() - RESIZE_LIMIT, right = this->width() - RESIZE_LIMIT;
90+
if (x < RESIZE_LIMIT && y < RESIZE_LIMIT){
3391
posCursor = event->globalPos() - this->geometry().topLeft();
3492
locked = LockMoveType::TopLeft;
3593
}
36-
else if (x < 5 && y > bottom){
94+
else if (x < RESIZE_LIMIT && y > bottom){
3795
posCursor = event->globalPos() - this->geometry().bottomLeft();
3896
locked = LockMoveType::BottomLeft;
3997
}
40-
else if (x > right && y < 5){
98+
else if (x > right && y < RESIZE_LIMIT){
4199
posCursor = event->globalPos() - this->geometry().topRight();
42100
locked = LockMoveType::TopRight;
43101
}
44102
else if (x > right && y > bottom){
45103
posCursor = event->globalPos() - this->geometry().bottomRight();
46104
locked = LockMoveType::BottomRight;
47105
}
48-
else if (x < 5 || y < 5){
106+
else if (x < RESIZE_LIMIT || y < RESIZE_LIMIT){
49107
posCursor = event->globalPos() - this->geometry().topLeft();
50-
locked = x < 5 ? LockMoveType::Left : LockMoveType::Top;
108+
locked = x < RESIZE_LIMIT ? LockMoveType::Left : LockMoveType::Top;
51109
}
52110
else if (x > right || y > bottom){
53111
posCursor = event->globalPos() - this->geometry().bottomRight();
@@ -57,7 +115,7 @@ void frmMain::mousePressEvent(QMouseEvent *event)
57115
}
58116
}
59117

60-
void frmMain::undefMouseMoveEvent(QObject* object, QMouseEvent* event){
118+
void NMainWindow::undefMouseMoveEvent(QObject* object, QMouseEvent* event){
61119
if (locked != LockMoveType::None){
62120
switch (locked) {
63121
case LockMoveType::TopLeft:
@@ -96,49 +154,49 @@ void frmMain::undefMouseMoveEvent(QObject* object, QMouseEvent* event){
96154
return;
97155
}
98156

99-
int x = event->x(), y = event->y(), right = this->width() - 5;
157+
int x = event->x(), y = event->y(), right = this->width() - RESIZE_LIMIT;
100158
if (object->objectName() == "statusBar"){
101-
if (x < 5 && y > 14){
159+
if (x < RESIZE_LIMIT && y > (19 - RESIZE_LIMIT)){
102160
this->setCursor(QCursor(Qt::SizeBDiagCursor));
103161
return;
104162
}
105-
else if (x > right && y > 14){
163+
else if (x > right && y > (19 - RESIZE_LIMIT)){
106164
this->setCursor(QCursor(Qt::SizeFDiagCursor));
107165
return;
108166
}
109-
else if (y > 14){
167+
else if (y > (19 - RESIZE_LIMIT)){
110168
this->setCursor(QCursor(Qt::SizeVerCursor));
111169
return;
112170
}
113171
}
114172
else if (object->objectName() == "titleBar"){
115-
if (x < 5 && y < 5){
173+
if (x < RESIZE_LIMIT && y < RESIZE_LIMIT){
116174
this->setCursor(QCursor(Qt::SizeFDiagCursor));
117175
return;
118176
}
119-
if (x > right && y < 5){
177+
if (x > right && y < RESIZE_LIMIT){
120178
this->setCursor(QCursor(Qt::SizeBDiagCursor));
121179
return;
122180
}
123-
else if (y < 5){
181+
else if (y < RESIZE_LIMIT){
124182
this->setCursor(QCursor(Qt::SizeVerCursor));
125183
return;
126184
}
127185
}
128-
if (x < 5 || x > right){
186+
if (x < RESIZE_LIMIT || x > right){
129187
this->setCursor(QCursor(Qt::SizeHorCursor));
130188
}
131189
else {
132190
this->setCursor(QCursor(Qt::ArrowCursor));
133191
}
134192
}
135193

136-
void frmMain::mouseReleaseEvent(QMouseEvent *event){
194+
void NMainWindow::mouseReleaseEvent(QMouseEvent *event){
137195
locked = LockMoveType::None;
138196
event->accept();
139197
}
140198

141-
bool frmMain::eventFilter(QObject* object, QEvent* event)
199+
bool NMainWindow::eventFilter(QObject* object, QEvent* event)
142200
{
143201
if(event->type() == QEvent::MouseMove)
144202
undefMouseMoveEvent(object, static_cast<QMouseEvent*>(event));
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*-------------------------------------------------
2+
#
3+
# Project developed by Nintersoft team
4+
# Developer: Mauro Mascarenhas de Araújo
5+
# Contact: mauro.mascarenhas@nintersoft.com
6+
# License: Nintersoft Open Source Code Licence
7+
# Date: 31 of May of 2018
8+
#
9+
------------------------------------------------- */
10+
11+
#ifndef NMAINWINDOW_H
12+
#define NMAINWINDOW_H
13+
14+
#include <QMainWindow>
15+
#include <QMouseEvent>
16+
#include <QPoint>
17+
#include <QDebug>
18+
19+
#include "titlebar.h"
20+
21+
namespace Ui {
22+
class NMainWindow;
23+
}
24+
25+
class NMainWindow : public QMainWindow
26+
{
27+
Q_OBJECT
28+
29+
public:
30+
explicit NMainWindow(QWidget *parent = 0);
31+
~NMainWindow();
32+
33+
void setCustomWidgets(QWidget *newCentralWidget, QStatusBar *newStatusBar);
34+
void setNewCentralWidget(QWidget *newCentralWidget);
35+
void setCustomStatusBar(QStatusBar *newStatusBar);
36+
37+
void setCloseButtonEnabled(bool enable);
38+
void setMaximizeButtonEnabled(bool enable);
39+
void setMinimizeButtonEnabled(bool enable);
40+
41+
protected:
42+
void mousePressEvent(QMouseEvent *event);
43+
void mouseReleaseEvent(QMouseEvent *event);
44+
void undefMouseMoveEvent(QObject *object, QMouseEvent* event);
45+
bool eventFilter(QObject *watched, QEvent *event);
46+
47+
enum LockMoveType{
48+
Left,
49+
Right,
50+
Top,
51+
Bottom,
52+
TopLeft,
53+
TopRight,
54+
BottomLeft,
55+
BottomRight,
56+
None
57+
};
58+
59+
private:
60+
Ui::NMainWindow *ui;
61+
const int RESIZE_LIMIT;
62+
63+
QPoint posCursor;
64+
LockMoveType locked;
65+
};
66+
67+
#endif // NMAINWINDOW_H

0 commit comments

Comments
 (0)