Skip to content

Commit 8073888

Browse files
authored
Merge pull request #261 from Bali10050/feature
Feature
2 parents fd6a59a + cf33536 commit 8073888

File tree

3 files changed

+158
-21
lines changed

3 files changed

+158
-21
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.29
1+
0.5.30

kstyle/CMakeLists.txt

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
################# includes #################
22
include_directories(
3-
animations
4-
debug
3+
animations
4+
debug
5+
${CMAKE_SOURCE_DIR}/libdarklycommon
6+
${CMAKE_BINARY_DIR}/libdarklycommon
57
)
68

7-
include_directories(${CMAKE_SOURCE_DIR}/libdarklycommon)
8-
include_directories(${CMAKE_BINARY_DIR}/libdarklycommon)
9-
109
################# configuration #################
1110
configure_file(config-darkly.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-darkly.h)
1211

@@ -59,21 +58,34 @@ kconfig_add_kcfg_files(darkly_PART_SRCS darklystyleconfigdata.kcfgc)
5958

6059
add_library(darkly${QT_MAJOR_VERSION} MODULE ${darkly_PART_SRCS})
6160

61+
################# find Qt modules #################
62+
if(QT_MAJOR_VERSION EQUAL 6)
63+
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Quick QuickWidgets)
64+
else()
65+
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Quick QuickWidgets)
66+
endif()
67+
68+
################# link Qt libraries #################
6269
target_link_libraries(darkly${QT_MAJOR_VERSION}
70+
PRIVATE
6371
Qt${QT_MAJOR_VERSION}::Core
6472
Qt${QT_MAJOR_VERSION}::Gui
6573
Qt${QT_MAJOR_VERSION}::Widgets
6674
Qt${QT_MAJOR_VERSION}::DBus
75+
Qt${QT_MAJOR_VERSION}::Quick
6776
)
6877

6978
if( DARKLY_HAVE_QTQUICK )
7079
target_link_libraries(darkly${QT_MAJOR_VERSION}
71-
Qt${QT_MAJOR_VERSION}::Quick
72-
KF${QT_MAJOR_VERSION}::CoreAddons
80+
PRIVATE
81+
Qt${QT_MAJOR_VERSION}::QuickWidgets
82+
KF${QT_MAJOR_VERSION}::CoreAddons
7383
)
7484
endif()
7585

86+
################# link KDE Frameworks #################
7687
target_link_libraries(darkly${QT_MAJOR_VERSION}
88+
PRIVATE
7789
KF${QT_MAJOR_VERSION}::CoreAddons
7890
KF${QT_MAJOR_VERSION}::ConfigCore
7991
KF${QT_MAJOR_VERSION}::ConfigGui
@@ -83,29 +95,29 @@ target_link_libraries(darkly${QT_MAJOR_VERSION}
8395
)
8496

8597
if(QT_MAJOR_VERSION STREQUAL "5")
86-
target_link_libraries(darkly5 KF5::ConfigWidgets)
87-
if (DARKLY_HAVE_QTQUICK)
88-
target_link_libraries(darkly5 KF5::Kirigami2)
98+
target_link_libraries(darkly${QT_MAJOR_VERSION} PRIVATE KF5::ConfigWidgets)
99+
if(DARKLY_HAVE_QTQUICK)
100+
target_link_libraries(darkly${QT_MAJOR_VERSION} PRIVATE KF5::Kirigami2)
89101
endif()
90102
else()
91-
target_link_libraries(darkly6 KF6::ColorScheme)
92-
if (DARKLY_HAVE_QTQUICK)
93-
target_link_libraries(darkly6 KF6::KirigamiPlatform)
103+
target_link_libraries(darkly${QT_MAJOR_VERSION} PRIVATE KF6::ColorScheme)
104+
if(DARKLY_HAVE_QTQUICK)
105+
target_link_libraries(darkly${QT_MAJOR_VERSION} PRIVATE KF6::KirigamiPlatform)
94106
endif()
95107
endif()
96108

109+
################# link internal library #################
110+
target_link_libraries(darkly${QT_MAJOR_VERSION} PRIVATE darklycommon${QT_MAJOR_VERSION})
97111

98-
target_link_libraries(darkly${QT_MAJOR_VERSION} darklycommon${QT_MAJOR_VERSION})
99-
112+
################# KDE style integration #################
100113
if(KF${QT_MAJOR_VERSION}FrameworkIntegration_FOUND)
101-
target_link_libraries(darkly${QT_MAJOR_VERSION} KF${QT_MAJOR_VERSION}::Style)
114+
target_link_libraries(darkly${QT_MAJOR_VERSION} PRIVATE KF${QT_MAJOR_VERSION}::Style)
102115
endif()
103116

104-
105117
if (WIN32)
106118
# As stated in https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants M_PI only gets defined
107119
# when if _USE_MATH_DEFINES is defined
108-
target_compile_definitions(darkly PRIVATE _USE_MATH_DEFINES _BSD_SOURCE)
120+
target_compile_definitions(darkly${QT_MAJOR_VERSION} PRIVATE _USE_MATH_DEFINES _BSD_SOURCE)
109121
endif()
110122

111123

kstyle/darklystyle.cpp

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <QTreeView>
7171
#include <QWidgetAction>
7272
#include <QWindow>
73+
#include <QQuickWidget>
7374

7475
#if DARKLY_HAVE_QTQUICK
7576
#include <QQuickWindow>
@@ -258,6 +259,86 @@ void Style::polish(QApplication *app)
258259
ParentStyleClass::polish(app);
259260
}
260261

262+
//______________________________________________________________
263+
class ParentResizeFilter : public QObject {
264+
public:
265+
explicit ParentResizeFilter(QWidget* overlay)
266+
: QObject(overlay), m_overlay(overlay) {}
267+
268+
protected:
269+
bool eventFilter(QObject* watched, QEvent* event) override {
270+
if (event->type() == QEvent::Resize && m_overlay && m_overlay->parentWidget() == watched) {
271+
m_overlay->setGeometry(m_overlay->parentWidget()->rect());
272+
m_overlay->update();
273+
}
274+
// call base implementation
275+
return QObject::eventFilter(watched, event);
276+
}
277+
278+
private:
279+
QWidget* m_overlay;
280+
};
281+
282+
class RoundedOuterOutlineOverlay : public QWidget {
283+
public:
284+
RoundedOuterOutlineOverlay(
285+
QWidget* parent,
286+
bool isDolphin,
287+
int radius = StyleConfigData::cornerRadius(),
288+
int thickness = StyleConfigData::cornerRadius() * 2)
289+
: QWidget(parent)
290+
, m_isDolphin(isDolphin)
291+
, m_radius(radius)
292+
, m_thickness(thickness)
293+
{
294+
setAttribute(Qt::WA_TransparentForMouseEvents);
295+
setAttribute(Qt::WA_TranslucentBackground);
296+
setAttribute(Qt::WA_NoSystemBackground);
297+
show();
298+
}
299+
300+
protected:
301+
void paintEvent(QPaintEvent*) override {
302+
if (!parentWidget()) return;
303+
304+
QPainter painter(this);
305+
painter.setRenderHint(QPainter::Antialiasing);
306+
307+
QPalette::ColorGroup group =
308+
parentWidget()->isActiveWindow()
309+
? QPalette::Active
310+
: QPalette::Inactive;
311+
312+
QColor outlineColor =
313+
parentWidget()->style()->standardPalette().color(group, QPalette::Window);
314+
315+
painter.setPen(Qt::NoPen);
316+
painter.setBrush(outlineColor);
317+
318+
QPainterPath path;
319+
path.addRect(rect());
320+
321+
QRectF innerRect = rect();
322+
innerRect.adjust(1, 1, m_isDolphin ? -5 : -1, -2);
323+
324+
path.addRoundedRect(innerRect, m_radius, m_radius);
325+
path.setFillRule(Qt::OddEvenFill);
326+
327+
if (outlineColor.alpha() < 255)
328+
{
329+
painter.setCompositionMode(QPainter::CompositionMode_Clear);
330+
painter.drawPath(path);
331+
}
332+
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
333+
painter.drawPath(path);
334+
}
335+
336+
private:
337+
bool m_isDolphin;
338+
int m_radius;
339+
int m_thickness;
340+
};
341+
261342
//______________________________________________________________
262343
void Style::polish(QWidget *widget)
263344
{
@@ -300,6 +381,26 @@ void Style::polish(QWidget *widget)
300381
}
301382
}
302383

384+
if (qobject_cast<QLabel*>(widget)) {
385+
QWidget* parent = widget->parentWidget();
386+
if (!parent)
387+
return;
388+
389+
while (parent) {
390+
if (parent->inherits("KMessageWidget")) {
391+
if (!parent->property("_darklyRoundedOverlay").isValid())
392+
{
393+
auto overlay = new RoundedOuterOutlineOverlay(parent, _isDolphin, StyleConfigData::cornerRadius(), StyleConfigData::cornerRadius() * 2);
394+
overlay->lower();
395+
parent->installEventFilter(new ParentResizeFilter(overlay));
396+
parent->setProperty("_darklyRoundedOverlay", QVariant::fromValue(static_cast<QObject*>(overlay)));
397+
}
398+
break;
399+
}
400+
parent = parent->parentWidget();
401+
}
402+
}
403+
303404
// enforce translucency for drag and drop window
304405
if (widget->testAttribute(Qt::WA_X11NetWmWindowTypeDND) && _helper->compositingActive()) {
305406
widget->setAttribute(Qt::WA_TranslucentBackground);
@@ -399,12 +500,36 @@ void Style::polish(QWidget *widget)
399500
}
400501

401502
// hack Dolphin's view
402-
if (_isDolphin && qobject_cast<QAbstractScrollArea *>(getParent(widget, 2))
403-
&& !qobject_cast<QAbstractScrollArea *>(getParent(widget, 3))) {
503+
if ((_isDolphin && qobject_cast<QAbstractScrollArea *>(getParent(widget, 2))
504+
&& !qobject_cast<QAbstractScrollArea *>(getParent(widget, 3))))
505+
{
404506
if (widget->autoFillBackground())
405507
widget->setAutoFillBackground(false);
406508
}
407509

510+
if (widget->inherits("QQuickWidget")) {
511+
// Check if it is a child of FocusHackWidget
512+
QWidget* parent = widget->parentWidget();
513+
bool isChildOfFocusHack = false;
514+
while (parent) {
515+
if (parent->inherits("FocusHackWidget")) {
516+
isChildOfFocusHack = true;
517+
break;
518+
}
519+
parent = parent->parentWidget();
520+
}
521+
522+
if (isChildOfFocusHack) {
523+
auto quickWidget = qobject_cast<QQuickWidget*>(widget);
524+
if (quickWidget) {
525+
quickWidget->setClearColor(Qt::transparent);
526+
}
527+
528+
widget->setAttribute(Qt::WA_TranslucentBackground);
529+
widget->setAttribute(Qt::WA_OpaquePaintEvent, false);
530+
}
531+
}
532+
408533
// scrollarea polishing is somewhat complex. It is moved to a dedicated method
409534
polishScrollArea(qobject_cast<QAbstractScrollArea *>(widget));
410535

0 commit comments

Comments
 (0)