Skip to content

Commit

Permalink
Merge pull request #52 from DeltaCopy/feature/cleanup
Browse files Browse the repository at this point in the history
Cleaned up compiler warnings
  • Loading branch information
Bali10050 authored Dec 2, 2024
2 parents 790553e + 5359894 commit 34a3c8a
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 68 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ cd Lightly
sudo zypper in --no-recommends git ninja cmake kf6-extra-cmake-modules kf6-kconfig-devel \
kf6-frameworkintegration-devel gmp-ecm-devel kf6-kconfigwidgets-devel \
kf6-kguiaddons-devel kf6-ki18n-devel kf6-kiconthemes-devel kf6-kwindowsystem-devel \
kf6-kcolorscheme-devel kf6-kcoreaddons-devel kf6-kcmutils-devel kcmutils \
kf6-kcolorscheme-devel kf6-kcoreaddons-devel kf6-kcmutils-devel \
qt6-quick-devel kf6-kirigami-devel qt6-base-devel kdecoration6-devel \
qt6-tools qt6-widgets-devel gcc-c++ extra-cmake-modules libQt5Gui-devel \
libQt5DBus-devel libqt5-qttools-devel libqt5-qtx11extras-devel \
Expand Down
5 changes: 5 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ remove_qt6_files() {
"/usr/lib/cmake/${PROJECT}/${PROJECT}ConfigVersion.cmake"
"/usr/share/color-schemes/${_PROJECT}.colors"
/usr/lib/cmake/"${PROJECT^}"
"/usr/lib/x86_64-linux-gnu/qt6/plugins/org.kde.kdecoration2/org.kde.${PROJECT}.so"
"/usr/lib/x86_64-linux-gnu/qt6/plugins/kstyle_config/${PROJECT}styleconfig.so"
"/usr/lib/x86_64-linux-gnu/qt6/plugins/org.kde.kdecoration2.kcm/kcm_${PROJECT}decoration.so"
"/usr/lib/x86_64-linux-gnu/qt6/plugins/styles/${PROJECT}6.so"
)

for f in ${files[@]}; do
Expand All @@ -91,6 +95,7 @@ remove_qt5_files() {
"/usr/lib64/lib${PROJECT}common5.so.6"
"/usr/lib/lib${PROJECT}common5.so.6"
"/usr/lib64/qt/plugins/styles/${PROJECT}5.so"
"/usr/lib/x86_64-linux-gnu/qt5/plugins/styles/${PROJECT}5.so"
)

for f in ${files[@]}; do
Expand Down
61 changes: 39 additions & 22 deletions kstyle/lightlyhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <QDialog>
#include <algorithm>

#include <QEvent>

//#include <QDebug>

namespace Lightly
Expand All @@ -49,24 +51,41 @@ namespace Lightly
static const qreal arrowShade = 0.15;

//____________________________________________________________________
Helper::Helper( KSharedConfig::Ptr config, QObject *parent ):
_config( std::move( config ) )
PaletteChangedEventFilter::PaletteChangedEventFilter(Helper *helper)
: QObject(helper)
, _helper(helper)
{

if ( qApp ) {
connect(qApp, &QApplication::paletteChanged, this, [this]() {
if (qApp->property("KDE_COLOR_SCHEME_PATH").isValid()) {
const auto path = qApp->property("KDE_COLOR_SCHEME_PATH").toString();
KConfig config(path, KConfig::SimpleConfig);
KConfigGroup group( config.group("WM") );
const QPalette palette( QApplication::palette() );
_activeTitleBarColor = group.readEntry( "activeBackground", palette.color( QPalette::Active, QPalette::Highlight ) );
_activeTitleBarTextColor = group.readEntry( "activeForeground", palette.color( QPalette::Active, QPalette::HighlightedText ) );
_inactiveTitleBarColor = group.readEntry( "inactiveBackground", palette.color( QPalette::Disabled, QPalette::Highlight ) );
_inactiveTitleBarTextColor = group.readEntry( "inactiveForeground", palette.color( QPalette::Disabled, QPalette::HighlightedText ) );
}
});
}

//____________________________________________________________________
bool PaletteChangedEventFilter::eventFilter(QObject *watched, QEvent *event) {
if (event->type() != QEvent::ApplicationPaletteChange || watched != qApp) {
return QObject::eventFilter(watched, event);
}
if (!qApp->property("KDE_COLOR_SCHEME_PATH").isValid()) {
return QObject::eventFilter(watched, event);
}
const auto path = qApp->property("KDE_COLOR_SCHEME_PATH").toString();
if (!path.isEmpty()) {
KConfig config(path, KConfig::SimpleConfig);
KConfigGroup group(config.group(QStringLiteral("WM")));
const QPalette palette(QApplication::palette());
_helper->_activeTitleBarColor = group.readEntry("activeBackground", palette.color(QPalette::Active, QPalette::Highlight));
_helper->_activeTitleBarTextColor = group.readEntry("activeForeground", palette.color(QPalette::Active, QPalette::HighlightedText));
_helper->_inactiveTitleBarColor = group.readEntry("inactiveBackground", palette.color(QPalette::Disabled, QPalette::Highlight));
_helper->_inactiveTitleBarTextColor = group.readEntry("inactiveForeground", palette.color(QPalette::Disabled, QPalette::HighlightedText));
}
return QObject::eventFilter(watched, event);
}



//____________________________________________________________________
Helper::Helper( KSharedConfig::Ptr config, QObject *parent )
: QObject(parent)
, _config( std::move( config ) )
, _eventFilter(new PaletteChangedEventFilter(this))
{
}

//____________________________________________________________________
Expand Down Expand Up @@ -142,7 +161,7 @@ namespace Lightly
{ return KColorUtils::mix( hoverColor( palette ), palette.color( QPalette::ButtonText ), 0.15 ); }

//____________________________________________________________________
QColor Helper::sidePanelOutlineColor( const QPalette& palette, bool hasFocus, qreal opacity, AnimationMode mode ) const
QColor Helper::sidePanelOutlineColor( const QPalette& palette ) const
{

QColor outline( qGray(palette.color( QPalette::Window ).rgb()) > 150 ? QColor(0,0,0,20) : QColor(0,0,0,50) );
Expand Down Expand Up @@ -465,7 +484,7 @@ namespace Lightly
//______________________________________________________________________________
void Helper::renderFrame(
QPainter* painter, const QRect& rect,
const QColor& color, const QPalette& palette, const bool windowActive, const bool enabled ) const
const QColor& color, const bool windowActive, const bool enabled ) const
{

painter->setRenderHint( QPainter::Antialiasing );
Expand Down Expand Up @@ -1514,16 +1533,14 @@ namespace Lightly
//______________________________________________________________________________
void Helper::renderProgressBarGroove(
QPainter* painter, const QRect& rect,
const QColor& color, const bool isContent ) const
const QColor& color ) const
{

// setup painter
painter->setRenderHint( QPainter::Antialiasing, true );

const QRectF baseRect( rect );

int thickness = Metrics::ProgressBar_Thickness;
if( !isContent ) thickness = qMax(Metrics::ProgressBar_Thickness-2, 0);

const qreal radius(0.5 * static_cast<qreal>(Metrics::ProgressBar_Thickness));

// content
Expand Down
26 changes: 22 additions & 4 deletions kstyle/lightlyhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

namespace Lightly
{
class PaletteChangedEventFilter;

//* lightly style helper class.
/** contains utility functions used at multiple places in both lightly style and lightly window decoration */
Expand Down Expand Up @@ -108,7 +109,7 @@ namespace Lightly
QColor buttonHoverOutlineColor( const QPalette& ) const;

//* side panel outline color, using animations
QColor sidePanelOutlineColor( const QPalette&, bool hasFocus = false, qreal opacity = AnimationData::OpacityInvalid, AnimationMode = AnimationNone ) const;
QColor sidePanelOutlineColor( const QPalette& ) const;

//* frame background color
QColor frameBackgroundColor( const QPalette& palette ) const
Expand Down Expand Up @@ -163,7 +164,7 @@ namespace Lightly
void renderFocusLine( QPainter*, const QRect&, const QColor& ) const;

//* generic frame
void renderFrame( QPainter*, const QRect&, const QColor& color, const QPalette& palette, const bool windowActive, const bool enabled = true ) const;
void renderFrame( QPainter*, const QRect&, const QColor& color, const bool windowActive, const bool enabled = true ) const;

//* side panel frame
void renderSidePanelFrame( QPainter*, const QRect&, const QColor& outline, Side ) const;
Expand Down Expand Up @@ -232,11 +233,11 @@ namespace Lightly
void renderDialContents( QPainter*, const QRect&, const QColor&, qreal first, qreal second ) const;

//* progress bar groove
void renderProgressBarGroove( QPainter*, const QRect&, const QColor&, const bool isContent = false ) const;
void renderProgressBarGroove( QPainter*, const QRect&, const QColor& ) const;

//* progress bar contents
void renderProgressBarContents( QPainter* painter, const QRect& rect, const QColor& color ) const
{ return renderProgressBarGroove( painter, rect, color, true ); }
{ return renderProgressBarGroove( painter, rect, color ); }

//* progress bar contents (animated)
void renderProgressBarBusyContents( QPainter* painter, const QRect& rect, const QColor& first, const QColor& second, bool horizontal, bool reverse, int progress ) const;
Expand Down Expand Up @@ -334,6 +335,9 @@ namespace Lightly
KStatefulBrush _windowAlternateBackgroundBrush;
//@}

//* event filter
PaletteChangedEventFilter *_eventFilter;

//*@name windeco colors
//@{
QColor _activeTitleBarColor;
Expand All @@ -344,6 +348,20 @@ namespace Lightly

mutable bool _cachedAutoValid = false;
friend class ToolsAreaManager;
friend class PaletteChangedEventFilter;
};

class PaletteChangedEventFilter : public QObject {
Q_OBJECT

public:
explicit PaletteChangedEventFilter(Helper *);

protected:
bool eventFilter(QObject *watched, QEvent *event) override;

private:
Helper *_helper;
};

}
Expand Down
45 changes: 26 additions & 19 deletions kstyle/lightlysplitterproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,27 +254,30 @@ namespace Lightly
QMouseEvent copy(
mouseEvent->type(),
_hook,
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
mouseEvent->globalPosition().toPoint(),
#endif
mouseEvent->button(),
mouseEvent->buttons(), mouseEvent->modifiers());
mouseEvent->buttons(),
mouseEvent->modifiers());

QCoreApplication::sendEvent( _splitter.data(), &copy );

} else {

// map event position to current splitter and post.
QMouseEvent copy(mouseEvent->type(),
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QMouseEvent copy(mouseEvent->type(),
_splitter.data()->mapFromGlobal( mouseEvent->globalPosition() ),
mouseEvent->button(),
mouseEvent->buttons(),
mouseEvent->modifiers());
_splitter.data()->mapFromGlobal(mouseEvent->globalPosition().toPoint()),
#else
QMouseEvent copy(mouseEvent->type(),
_splitter.data()->mapFromGlobal(mouseEvent->globalPos()),
mouseEvent->button(),
mouseEvent->buttons(),
mouseEvent->modifiers());
_splitter.data()->mapFromGlobal(mouseEvent->globalPos()),
#endif
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
mouseEvent->globalPosition().toPoint(),
#endif
mouseEvent->button(),
mouseEvent->buttons(),
mouseEvent->modifiers());

QCoreApplication::sendEvent( _splitter.data(), &copy );

Expand Down Expand Up @@ -365,15 +368,19 @@ namespace Lightly
hide();
parentWidget()->setUpdatesEnabled(true);

// send hover event
if( _splitter )
{
QHoverEvent hoverEvent(
qobject_cast<QSplitterHandle*>(_splitter.data()) ? QEvent::HoverLeave : QEvent::HoverMove,
_splitter.data()->mapFromGlobal(QCursor::pos()), _hook);
QCoreApplication::sendEvent( _splitter.data(), &hoverEvent );
// send hover event
if (_splitter) {
// SplitterProxy intercepts HoverLeave/HoverMove events to _splitter,
// but this is meant to reach it directly. Unset _splitter to stop interception.
auto splitter = _splitter;
_splitter.clear();

QHoverEvent hoverEvent(qobject_cast<QSplitterHandle *>(splitter.data()) ? QEvent::HoverLeave : QEvent::HoverMove,
splitter.data()->mapFromGlobal(QCursor::pos()),
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
splitter.data()->mapFromGlobal(QCursor::pos()),
#endif
_hook);
QCoreApplication::sendEvent(splitter.data(), &hoverEvent);
}

// kill timer if any
Expand Down
39 changes: 20 additions & 19 deletions kstyle/lightlystyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,17 +1600,19 @@ Style::Style()
if( !scrollBar->rect().contains( position ) ) continue;

// copy event, send and return
QMouseEvent copy(
mouseEvent->type(),
position,
mouseEvent->button(),
mouseEvent->buttons(), mouseEvent->modifiers());

QCoreApplication::sendEvent( scrollBar, &copy );
event->setAccepted( true );
return true;
QMouseEvent copy(mouseEvent->type(),
position,
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
QCursor::pos(),
#endif
mouseEvent->button(),
mouseEvent->buttons(),
mouseEvent->modifiers());

}
QCoreApplication::sendEvent(scrollBar, &copy);
event->setAccepted(true);
return true;
}

break;

Expand Down Expand Up @@ -1686,7 +1688,7 @@ Style::Style()

} else if( StyleConfigData::dockWidgetDrawFrame() && (dockWidget->features() & (QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable))){

_helper->renderFrame( &painter, rect, background, palette, windowActive );
_helper->renderFrame( &painter, rect, background, windowActive );

} else {

Expand Down Expand Up @@ -3639,14 +3641,14 @@ Style::Style()
_animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus );

// retrieve animation mode and opacity
const AnimationMode mode( _animations->inputWidgetEngine().frameAnimationMode( widget ) );
const qreal opacity( _animations->inputWidgetEngine().frameOpacity( widget ) );
_animations->inputWidgetEngine().frameAnimationMode( widget ) ;
_animations->inputWidgetEngine().frameOpacity( widget ) ;

// render
if( !StyleConfigData::sidePanelDrawFrame() && widget && widget->property( PropertyNames::sidePanelView ).toBool() )
{

const auto outline( _helper->sidePanelOutlineColor( palette, hasFocus, opacity, mode ) );
const auto outline( _helper->sidePanelOutlineColor( palette ) );
const bool reverseLayout( option->direction == Qt::RightToLeft );
const Side side( reverseLayout ? SideRight : SideLeft );
if( (widget->window()->windowFlags() & Qt::WindowType_Mask) == Qt::Dialog )
Expand Down Expand Up @@ -3684,7 +3686,7 @@ Style::Style()
}*/

const auto background( isTitleWidget ? palette.color( widget->backgroundRole() ) : palette.color( QPalette::Base ) );
_helper->renderFrame( painter, rect, background, palette, windowActive, enabled );
_helper->renderFrame( painter, rect, background, windowActive, enabled );

}

Expand Down Expand Up @@ -3808,7 +3810,7 @@ Style::Style()
}

//______________________________________________________________
bool Style::drawFrameGroupBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget) const
bool Style::drawFrameGroupBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{

// cast option and check
Expand Down Expand Up @@ -5511,8 +5513,8 @@ Style::Style()
const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() );

_animations->inputWidgetEngine().updateState( widget, AnimationHover, selected );
const AnimationMode mode( _animations->inputWidgetEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->inputWidgetEngine().buttonOpacity( widget ) );
_animations->inputWidgetEngine().buttonAnimationMode( widget );
_animations->inputWidgetEngine().buttonOpacity( widget );

// render hover and focus
if( selected || sunken )
Expand Down Expand Up @@ -5554,7 +5556,6 @@ Style::Style()
// checkbox state

CheckBoxState state( menuItemOption->checked ? CheckOn : CheckOff );
const bool active( menuItemOption->checked );
//const auto color( _helper->checkBoxIndicatorColor( palette, false, enabled && active ) );
const auto background( state == CheckOn ? palette.color( QPalette::Highlight ) : palette.color( QPalette::Button ) );
//_helper->renderCheckBoxBackground( painter, checkBoxRect, palette.color( QPalette::Window ), sunken ); //not needed
Expand Down
13 changes: 10 additions & 3 deletions kstyle/lightlywindowmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ namespace Lightly
post some mouseRelease event to the target, in order to counter balance
the mouse press that triggered the drag. Note that it triggers a resetDrag
*/
QMouseEvent mouseEvent( QEvent::MouseButtonRelease, _parent->_dragPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
qApp->sendEvent( _parent->_target.data(), &mouseEvent );
QMouseEvent mouseEvent(QEvent::MouseButtonRelease, _parent->_dragPoint, QCursor::pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);

return false;

Expand Down Expand Up @@ -464,7 +463,15 @@ namespace Lightly
auto localPoint( _dragPoint );
if( child ) localPoint = child->mapFrom( widget, localPoint );
else child = widget;
QMouseEvent localMouseEvent( QEvent::MouseMove, localPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QMouseEvent localMouseEvent(QEvent::MouseMove,
localPoint,
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
QCursor::pos(),
#endif
Qt::NoButton,
Qt::LeftButton,
Qt::NoModifier);
localMouseEvent.setTimestamp(mouseEvent->timestamp());
qApp->sendEvent( child, &localMouseEvent );

// never eat event
Expand Down

0 comments on commit 34a3c8a

Please sign in to comment.