Come cmake cleanups, added new class for close button.
This commit is contained in:
parent
4f0a4d2120
commit
baacd2c539
@ -288,6 +288,7 @@ set(APP_SOURCES
|
|||||||
src/gui/statusbar.cpp
|
src/gui/statusbar.cpp
|
||||||
src/gui/iconfactory.cpp
|
src/gui/iconfactory.cpp
|
||||||
src/gui/formcategorydetails.cpp
|
src/gui/formcategorydetails.cpp
|
||||||
|
src/gui/closebutton.cpp
|
||||||
|
|
||||||
# CORE sources.
|
# CORE sources.
|
||||||
src/core/debugging.cpp
|
src/core/debugging.cpp
|
||||||
@ -350,6 +351,7 @@ set(APP_HEADERS
|
|||||||
src/gui/messagesview.h
|
src/gui/messagesview.h
|
||||||
src/gui/statusbar.h
|
src/gui/statusbar.h
|
||||||
src/gui/formcategorydetails.h
|
src/gui/formcategorydetails.h
|
||||||
|
src/gui/closebutton.h
|
||||||
|
|
||||||
# CORE headers.
|
# CORE headers.
|
||||||
src/core/settings.h
|
src/core/settings.h
|
||||||
|
36
src/gui/closebutton.cpp
Normal file
36
src/gui/closebutton.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "gui/closebutton.h"
|
||||||
|
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
#include <QStyleOption>
|
||||||
|
|
||||||
|
|
||||||
|
CloseButton::CloseButton(QWidget *parent) : QToolButton(parent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseButton::~CloseButton() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseButton::paintEvent(QPaintEvent *e) {
|
||||||
|
QPainter p(this);
|
||||||
|
icon().paint(&p, QRect(QPoint(0, 0), iconSize()));
|
||||||
|
|
||||||
|
if (underMouse()) {
|
||||||
|
QStyleOptionFrameV3 style_option;
|
||||||
|
int frame_shape = QFrame::Sunken & QFrame::Shape_Mask;
|
||||||
|
|
||||||
|
style_option.init(this);
|
||||||
|
style_option.frameShape = QFrame::Shape(int(style_option.frameShape) |
|
||||||
|
QFrame::StyledPanel |
|
||||||
|
frame_shape);
|
||||||
|
style_option.rect = rect();
|
||||||
|
style_option.lineWidth = 1;
|
||||||
|
style_option.midLineWidth = 0;
|
||||||
|
|
||||||
|
style()->drawControl(QStyle::CE_ShapedFrame,
|
||||||
|
&style_option, &p,
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
}
|
20
src/gui/closebutton.h
Normal file
20
src/gui/closebutton.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef CLOSEBUTTON_H
|
||||||
|
#define CLOSEBUTTON_H
|
||||||
|
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
|
|
||||||
|
class CloseButton : public QToolButton {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Contructors and destructors.
|
||||||
|
explicit CloseButton(QWidget *parent = 0);
|
||||||
|
virtual ~CloseButton();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Custom look.
|
||||||
|
void paintEvent(QPaintEvent *e);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLOSEBUTTON_H
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
|
#include "gui/closebutton.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QToolButton>
|
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ TabBar::~TabBar() {
|
|||||||
void TabBar::setTabType(int index, const TabBar::TabType &type) {
|
void TabBar::setTabType(int index, const TabBar::TabType &type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TabBar::Closable: {
|
case TabBar::Closable: {
|
||||||
QToolButton *close_button = new QToolButton(this);
|
CloseButton *close_button = new CloseButton(this);
|
||||||
|
|
||||||
close_button->setIcon(IconThemeFactory::instance()->fromTheme("application-exit"));
|
close_button->setIcon(IconThemeFactory::instance()->fromTheme("application-exit"));
|
||||||
close_button->setToolTip(tr("Close this tab."));
|
close_button->setToolTip(tr("Close this tab."));
|
||||||
@ -48,7 +48,7 @@ void TabBar::setTabType(int index, const TabBar::TabType &type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::closeTabViaButton() {
|
void TabBar::closeTabViaButton() {
|
||||||
QToolButton *close_button = qobject_cast<QToolButton*>(sender());
|
CloseButton *close_button = qobject_cast<CloseButton*>(sender());
|
||||||
QTabBar::ButtonPosition button_position = static_cast<ButtonPosition>(style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition,
|
QTabBar::ButtonPosition button_position = static_cast<ButtonPosition>(style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition,
|
||||||
0,
|
0,
|
||||||
this));
|
this));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user