Skip to content

Commit 5425f2b

Browse files
author
Uwe Kindler
committed
Added missing FloatingWidgetTitleBar.cpp and missing stylesheet file for linux
1 parent e98fd5b commit 5425f2b

File tree

2 files changed

+283
-0
lines changed

2 files changed

+283
-0
lines changed

src/FloatingWidgetTitleBar.cpp

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*******************************************************************************
2+
** Qt Advanced Docking System
3+
** Copyright (C) 2017 Uwe Kindler
4+
**
5+
** This library is free software; you can redistribute it and/or
6+
** modify it under the terms of the GNU Lesser General Public
7+
** License as published by the Free Software Foundation; either
8+
** version 2.1 of the License, or (at your option) any later version.
9+
**
10+
** This library is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
** Lesser General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU Lesser General Public
16+
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
17+
******************************************************************************/
18+
19+
20+
//============================================================================
21+
/// \file FloatingWidgetTitleBar.cpp
22+
/// \author Uwe Kindler
23+
/// \date 13.05.2019
24+
/// \brief Implementation of CFloatingWidgetTitleBar class
25+
//============================================================================
26+
27+
//============================================================================
28+
// INCLUDES
29+
//============================================================================
30+
#include "FloatingWidgetTitleBar.h"
31+
32+
#include <iostream>
33+
34+
#include <QHBoxLayout>
35+
#include <QPushButton>
36+
#include <QToolButton>
37+
#include <QPixmap>
38+
#include <QStyle>
39+
#include <QMouseEvent>
40+
41+
#include "ads_globals.h"
42+
#include "ElidingLabel.h"
43+
#include "FloatingDockContainer.h"
44+
45+
namespace ads
46+
{
47+
48+
using tTabLabel = CElidingLabel;
49+
using tCloseButton = QPushButton;
50+
51+
52+
/**
53+
* @brief Private data class of public interface CFloatingWidgetTitleBar
54+
*/
55+
struct FloatingWidgetTitleBarPrivate
56+
{
57+
CFloatingWidgetTitleBar* _this; ///< public interface class
58+
QLabel* IconLabel = nullptr;
59+
tTabLabel* TitleLabel;
60+
tCloseButton* CloseButton = nullptr;
61+
CFloatingDockContainer* FloatingWidget = nullptr;
62+
eDragState DragState = DraggingInactive;
63+
64+
FloatingWidgetTitleBarPrivate(CFloatingWidgetTitleBar* _public) : _this(_public) {}
65+
66+
/**
67+
* Creates the complete layout including all controls
68+
*/
69+
void createLayout();
70+
};
71+
72+
73+
//============================================================================
74+
void FloatingWidgetTitleBarPrivate::createLayout()
75+
{
76+
TitleLabel = new tTabLabel();
77+
TitleLabel->setElideMode(Qt::ElideRight);
78+
TitleLabel->setText("DockWidget->windowTitle()");
79+
TitleLabel->setObjectName("floatingTitleLabel");
80+
TitleLabel->setAlignment(Qt::AlignLeft);
81+
82+
CloseButton = new tCloseButton();
83+
CloseButton->setObjectName("floatingTitleCloseButton");
84+
CloseButton->setFlat(true);
85+
//CloseButton->setAutoRaise(true);
86+
// The standard icons do does not look good on high DPI screens
87+
QIcon CloseIcon;
88+
QPixmap normalPixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, CloseButton);
89+
CloseIcon.addPixmap(normalPixmap, QIcon::Normal);
90+
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
91+
CloseButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
92+
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
93+
CloseButton->setVisible(true);
94+
CloseButton->setFocusPolicy(Qt::NoFocus);
95+
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));
96+
97+
QFontMetrics fm(TitleLabel->font());
98+
int Spacing = qRound(fm.height() / 4.0);
99+
100+
// Fill the layout
101+
QBoxLayout* Layout = new QBoxLayout(QBoxLayout::LeftToRight);
102+
Layout->setContentsMargins(6,0,0,0);
103+
Layout->setSpacing(0);
104+
_this->setLayout(Layout);
105+
Layout->addWidget(TitleLabel, 1);
106+
Layout->addSpacing(Spacing);
107+
Layout->addWidget(CloseButton);
108+
Layout->setAlignment(Qt::AlignCenter);
109+
110+
TitleLabel->setVisible(true);
111+
}
112+
113+
114+
//============================================================================
115+
CFloatingWidgetTitleBar::CFloatingWidgetTitleBar(CFloatingDockContainer *parent)
116+
: QWidget(parent),
117+
d(new FloatingWidgetTitleBarPrivate(this))
118+
{
119+
d->FloatingWidget = parent;
120+
d->createLayout();
121+
}
122+
123+
124+
//============================================================================
125+
CFloatingWidgetTitleBar::~CFloatingWidgetTitleBar()
126+
{
127+
delete d;
128+
}
129+
130+
131+
//============================================================================
132+
void CFloatingWidgetTitleBar::mousePressEvent(QMouseEvent* ev)
133+
{
134+
if (ev->button() == Qt::LeftButton)
135+
{
136+
d->DragState = DraggingFloatingWidget;
137+
d->FloatingWidget->startDragging(ev->pos(), d->FloatingWidget->size(), this);
138+
return;
139+
}
140+
Super::mousePressEvent(ev);
141+
}
142+
143+
144+
//============================================================================
145+
void CFloatingWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev)
146+
{
147+
d->DragState = DraggingInactive;
148+
Super::mouseReleaseEvent(ev);
149+
}
150+
151+
152+
//============================================================================
153+
void CFloatingWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev)
154+
{
155+
if (!(ev->buttons() & Qt::LeftButton) || DraggingInactive == d->DragState)
156+
{
157+
d->DragState = DraggingInactive;
158+
Super::mouseMoveEvent(ev);
159+
return;
160+
}
161+
162+
// move floating window
163+
if (DraggingFloatingWidget == d->DragState)
164+
{
165+
d->FloatingWidget->moveFloating();
166+
Super::mouseMoveEvent(ev);
167+
return;
168+
}
169+
Super::mouseMoveEvent(ev);
170+
}
171+
172+
173+
//============================================================================
174+
void CFloatingWidgetTitleBar::enableCloseButton(bool Enable)
175+
{
176+
d->CloseButton->setEnabled(Enable);
177+
}
178+
179+
180+
//============================================================================
181+
void CFloatingWidgetTitleBar::setTitle(const QString& Text)
182+
{
183+
d->TitleLabel->setText(Text);
184+
}
185+
186+
187+
} // namespace ads

src/stylesheets/default_linux.css

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
/*
3+
* Default style sheet on Windows Platforms
4+
* Note: Always use CSS-classes with and without "ads--" namespace to support Qt4 & Qt5
5+
*/
6+
7+
ads--CDockContainerWidget
8+
{
9+
background: palette(dark);
10+
}
11+
12+
ads--CDockContainerWidget QSplitter::handle
13+
{
14+
background: palette(dark);
15+
}
16+
17+
ads--CDockAreaWidget
18+
{
19+
background: palette(window);
20+
border: 1px solid white;
21+
}
22+
23+
ads--CDockAreaWidget #tabsMenuButton::menu-indicator
24+
{
25+
image: none;
26+
}
27+
28+
29+
ads--CDockWidgetTab
30+
{
31+
background: palette(window);
32+
border-color: palette(light);
33+
border-style: solid;
34+
border-width: 0 1px 0 0;
35+
padding: 0 0px;
36+
}
37+
38+
ads--CDockWidgetTab[activeTab="true"]
39+
{
40+
background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:0.5, stop:0 palette(window), stop:1 palette(light));
41+
/*background: palette(highlight);*/
42+
}
43+
44+
ads--CDockWidgetTab QLabel
45+
{
46+
color: palette(dark);
47+
}
48+
49+
ads--CDockWidgetTab[activeTab="true"] QLabel
50+
{
51+
color: palette(foreground);
52+
}
53+
54+
ads--CDockWidget
55+
{
56+
background: palette(light);
57+
border-color: palette(light);
58+
border-style: solid;
59+
border-width: 1px 0 0 0;
60+
}
61+
62+
#tabsMenuButton,
63+
#closeButton,
64+
#undockButton
65+
{
66+
padding: 0px -2px;
67+
}
68+
69+
70+
QScrollArea#dockWidgetScrollArea
71+
{
72+
padding: 0px;
73+
border: none;
74+
}
75+
76+
77+
#tabCloseButton
78+
{
79+
margin-top: 2px;
80+
background: none;
81+
border: none;
82+
padding: 0px -2px;
83+
}
84+
85+
#tabCloseButton:hover
86+
{
87+
border: 1px solid rgba(0, 0, 0, 32);
88+
background: rgba(0, 0, 0, 16);
89+
}
90+
91+
#tabCloseButton:pressed
92+
{
93+
background: rgba(0, 0, 0, 32);
94+
}
95+
96+

0 commit comments

Comments
 (0)