~dblsaiko/k90s

eb74cafcc1f706462579ec66ec6f46c236260f72 — 2xsaiko 3 years ago b8e1c20
Button thing!
4 files changed, 44 insertions(+), 1 deletions(-)

M appstyle/CMakeLists.txt
A appstyle/button.cpp
M appstyle/k90sstyl.cpp
M appstyle/k90sstyl.h
M appstyle/CMakeLists.txt => appstyle/CMakeLists.txt +1 -0
@@ 1,6 1,7 @@
project(k90sstyl)

set(k90sstyl_SRC
        button.cpp
        k90sstyl.cpp
        stylplug.cpp)


A appstyle/button.cpp => appstyle/button.cpp +18 -0
@@ 0,0 1,18 @@
#include "k90sstyl.h"

#include <QPalette>
#include <drawpanl.h>

void K90sStyle::draw_button_frame(QPainter* p, const QStyleOptionButton* opt, const QWidget* widget) const {
    p->setRenderHint(QPainter::Antialiasing);
    QColor color = opt->palette.color(QPalette::ColorGroup::Active, QPalette::ColorRole::Button);

    WindowTheme wt {
        .scale = 1,
        .background_color = color,
    };

    PanelType pt = (opt->state & State_Sunken) ? PANEL_TYPE_LOWERED : PANEL_TYPE_RAISED;

    draw_panel(p, wt, opt->rect, pt);
}

M appstyle/k90sstyl.cpp => appstyle/k90sstyl.cpp +22 -1
@@ 1,5 1,8 @@
#include "k90sstyl.h"

#include <QPainter>
#include <QStyleOptionButton>

K90sStyle::K90sStyle() : STYLE_CLASS() {

}


@@ 28,10 31,28 @@ void K90sStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption* o
    QCommonStyle::drawPrimitive(pe, opt, p, w);
}

#define CALL_CAST(element, target, call)                             \
    case element:                                                    \
        if (const auto* o = qstyleoption_cast<const target*>(opt)) { \
            call;                                                    \
        }                                                            \
        break;

void K90sStyle::drawControl(QStyle::ControlElement element, const QStyleOption* opt, QPainter* p, const QWidget* w) const {
    QCommonStyle::drawControl(element, opt, p, w);
    p->save();

    switch (element) {
        CALL_CAST(CE_PushButtonBevel, QStyleOptionButton, this->draw_button_frame(p, o, w))

        default:
            QCommonStyle::drawControl(element, opt, p, w);
    }

    p->restore();
}

#undef CALL_CAST

QRect K90sStyle::subElementRect(QStyle::SubElement r, const QStyleOption* opt, const QWidget* widget) const {
    return QCommonStyle::subElementRect(r, opt, widget);
}

M appstyle/k90sstyl.h => appstyle/k90sstyl.h +3 -0
@@ 2,6 2,7 @@
#define K90S_K90SSTYL_H

#include <QCommonStyle>
#include <QStyleOptionButton>

#ifdef USE_KF5



@@ 47,6 48,8 @@ public:

    int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption* option, const QWidget* widget) const override;

private:
    void draw_button_frame(QPainter* p, const QStyleOptionButton* opt, const QWidget* widget) const;

};