wip: icons
This commit is contained in:
parent
3239e60471
commit
8f864f3394
7 changed files with 128 additions and 10 deletions
|
|
@ -4,5 +4,7 @@
|
||||||
<file>assets/notificationAreaIcon.png</file>
|
<file>assets/notificationAreaIcon.png</file>
|
||||||
<file>assets/style.qss</file>
|
<file>assets/style.qss</file>
|
||||||
<file>assets/logo.ico</file>
|
<file>assets/logo.ico</file>
|
||||||
|
<file>assets/mute.svg</file>
|
||||||
|
<file>assets/unmute.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
taskkill /F /IM "MixerQ.exe"
|
taskkill /F /IM "MixerQ.exe"
|
||||||
taskkill /F /IM "MixerQd.exe"
|
taskkill /F /IM "MixerQd.exe"
|
||||||
qmake -o build\Makefile .\qtest.pro
|
qmake -o build\Makefile .\qtest.pro
|
||||||
mingw32-make.exe -C .\build -f Makefile.Release
|
REM mingw32-make.exe -C .\build -f Makefile.Release
|
||||||
mingw32-make.exe -C .\build -f Makefile.Debug
|
mingw32-make.exe -C .\build -f Makefile.Debug
|
||||||
makensis /DBUILDTYPE=release install\installer.nsi
|
REM makensis /DBUILDTYPE=release install\installer.nsi
|
||||||
makensis /DBUILDTYPE=debug install\installer.nsi
|
REM makensis /DBUILDTYPE=debug install\installer.nsi
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ LIBS += -lWinmm -lodbc32 -lodbccp32 -luuid -loleaut32 -lole32 -lshell32 -ladvapi
|
||||||
DEFINES += QT_LOGGING_TO_CONSOLE=1 WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0602
|
DEFINES += QT_LOGGING_TO_CONSOLE=1 WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0602
|
||||||
DEFINES_DEBUG += DEBUG
|
DEFINES_DEBUG += DEBUG
|
||||||
|
|
||||||
QT += widgets network
|
QT += widgets network svg
|
||||||
INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\back\reimpl" "$$PWD\src\cont"
|
INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\back\reimpl" "$$PWD\src\cont"
|
||||||
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\back\reimpl" "$$PWD\src\cont"
|
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\back\reimpl" "$$PWD\src\cont"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,36 @@ void ExtendedCheckBox::customEvent(QEvent* ev) {
|
||||||
QCheckBox::customEvent(ev);
|
QCheckBox::customEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExtendedCheckBox::paintEvent(QPaintEvent *event) {
|
||||||
|
QStylePainter p(this);
|
||||||
|
QStyleOptionButton opt;
|
||||||
|
initStyleOption(&opt);
|
||||||
|
opt.icon = this->icons;
|
||||||
|
p.drawControl((QStyle::ControlElement)CustomControlElement::CE_ExtendedCheckBox, opt);
|
||||||
|
//QStyle* style = QApplication::style();
|
||||||
|
//style->drawComplexControl((QStyle::ComplexControl)CC_MeterSlider, &sliderComplex2, &painter, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtendedCheckBox::addIcon(char* const path, QIcon::State state) {
|
||||||
|
QString str(path);
|
||||||
|
QSvgRenderer rr(str);
|
||||||
|
QPixmap pixmap(64, 64);
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
rr.render(&painter);
|
||||||
|
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||||
|
uint8_t a, r, g, b;
|
||||||
|
if (StylingHelper::argbToDiscreteValues(osh->getAccentColor(), &r, &g, &b, &a)) {
|
||||||
|
QColor color(r, g, b, a);
|
||||||
|
painter.fillRect(pixmap.rect(), color);
|
||||||
|
}
|
||||||
|
painter.end();
|
||||||
|
icons.addPixmap(pixmap, QIcon::Normal, state);
|
||||||
|
//this->setIcon(icons);
|
||||||
|
//icons.addFile(":/Icons/images/second.svg",QSize(32,32),QIcon::Normal,QIcon::Off);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) {
|
QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) {
|
||||||
//setGeometry ignores decoration size, theres others for that
|
//setGeometry ignores decoration size, theres others for that
|
||||||
QRect trayIconPos = this->trayIcon->geometry();
|
QRect trayIconPos = this->trayIcon->geometry();
|
||||||
|
|
@ -276,7 +306,7 @@ void MainWindow::compose(bool isVisible) {
|
||||||
* Setting correct widget widths and heights
|
* Setting correct widget widths and heights
|
||||||
*/
|
*/
|
||||||
log_to_file("[Compose]\n");
|
log_to_file("[Compose]\n");
|
||||||
screen = this->getCurrentScreen();
|
screen = StylingHelper::getCurrentScreen();
|
||||||
log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString());
|
log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString());
|
||||||
|
|
||||||
QRect screenRes = screen->geometry();
|
QRect screenRes = screen->geometry();
|
||||||
|
|
@ -336,7 +366,7 @@ void MainWindow::compose(bool isVisible) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QScreen* MainWindow::getCurrentScreen() {
|
QScreen* MainWindow::getCurrentScreen() {
|
||||||
//todo: Using cursor pos as screen detector. Flawed.
|
//note: Using cursor pos as screen detector. Flawed.
|
||||||
QPoint cursorPos = QCursor::pos();
|
QPoint cursorPos = QCursor::pos();
|
||||||
log_debugcpp("Cursor pos: " + std::to_string(cursorPos.ry()) + " " + std::to_string(cursorPos.rx()));
|
log_debugcpp("Cursor pos: " + std::to_string(cursorPos.ry()) + " " + std::to_string(cursorPos.rx()));
|
||||||
|
|
||||||
|
|
@ -363,7 +393,9 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
|
||||||
widgetLayout->getContentsMargins(&left, &top, &right, &bottom);
|
widgetLayout->getContentsMargins(&left, &top, &right, &bottom);
|
||||||
widgetLayout->setContentsMargins(0, top, 0, bottom);
|
widgetLayout->setContentsMargins(0, top, 0, bottom);
|
||||||
|
|
||||||
muteButton = new QCheckBox(this);
|
muteButton = new ExtendedCheckBox(this);
|
||||||
|
muteButton->addIcon(":/assets/mute.svg", QIcon::On);
|
||||||
|
muteButton->addIcon(":/assets/unmute.svg", QIcon::Off);
|
||||||
mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this);
|
mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this);
|
||||||
mainLabel->setToolTip(QString::fromStdWString(sh->getName()));
|
mainLabel->setToolTip(QString::fromStdWString(sh->getName()));
|
||||||
mainSlider = new MeterSlider(Qt::Horizontal, this);
|
mainSlider = new MeterSlider(Qt::Horizontal, this);
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,17 @@ public:
|
||||||
|
|
||||||
class ExtendedCheckBox : public QCheckBox {
|
class ExtendedCheckBox : public QCheckBox {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QIcon icons;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void customEvent(QEvent* ev) override;
|
void customEvent(QEvent* ev) override;
|
||||||
|
void paintEvent(QPaintEvent* event) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//c++11: this inherits all parent's constructors unconditionally
|
//c++11: this inherits all parent's constructors unconditionally
|
||||||
using QCheckBox::QCheckBox;
|
using QCheckBox::QCheckBox;
|
||||||
|
void addIcon(char* const path, QIcon::State state);
|
||||||
//alternative being calling parent ctor directly after declaring child ctor:
|
//alternative being calling parent ctor directly after declaring child ctor:
|
||||||
//B(int x) : A(x) { }
|
//B(int x) : A(x) { }
|
||||||
};
|
};
|
||||||
|
|
@ -68,7 +73,7 @@ private:
|
||||||
MeterSlider *mainSlider = nullptr;
|
MeterSlider *mainSlider = nullptr;
|
||||||
uint64_t idx;
|
uint64_t idx;
|
||||||
QHBoxLayout *widgetLayout = nullptr;
|
QHBoxLayout *widgetLayout = nullptr;
|
||||||
QCheckBox *muteButton = nullptr;
|
ExtendedCheckBox *muteButton = nullptr;
|
||||||
SessionHandler* sh;
|
SessionHandler* sh;
|
||||||
QTimer* volumePoller = nullptr;
|
QTimer* volumePoller = nullptr;
|
||||||
QSpacerItem* widthSpacer;
|
QSpacerItem* widthSpacer;
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QAbstractNativeEventFilter>
|
#include <QAbstractNativeEventFilter>
|
||||||
#include <QAbstractEventDispatcher>
|
#include <QAbstractEventDispatcher>
|
||||||
|
#include <QSvgRenderer>
|
||||||
//#include <QScrollbarStyleAnimation>
|
//#include <QScrollbarStyleAnimation>
|
||||||
//#include <QScrollBar>
|
//#include <QScrollBar>
|
||||||
/*
|
/*
|
||||||
|
|
@ -63,6 +64,10 @@ enum CustomComplexControl {
|
||||||
CC_MeterSlider = 0xf0000001
|
CC_MeterSlider = 0xf0000001
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum CustomControlElement {
|
||||||
|
CE_ExtendedCheckBox = 0xf0000001
|
||||||
|
};
|
||||||
|
|
||||||
namespace StylingHelper {
|
namespace StylingHelper {
|
||||||
|
|
||||||
static inline void setBackgroundColor(bool lightMode) {
|
static inline void setBackgroundColor(bool lightMode) {
|
||||||
|
|
@ -218,5 +223,32 @@ namespace StylingHelper {
|
||||||
return pal.color(QPalette::Base);
|
return pal.color(QPalette::Base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline QPixmap svg2Pixmap(const QString& svgContent,
|
||||||
|
const QSize& size,
|
||||||
|
QPainter::CompositionMode mode = QPainter::CompositionMode_SourceOver)
|
||||||
|
{
|
||||||
|
QSvgRenderer rr(svgContent);
|
||||||
|
QImage image(size.width(), size.height(), QImage::Format_ARGB32);
|
||||||
|
QPainter painter(&image);
|
||||||
|
painter.setCompositionMode(mode);
|
||||||
|
image.fill(Qt::transparent);
|
||||||
|
rr.render(&painter);
|
||||||
|
return QPixmap::fromImage(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QScreen* getCurrentScreen() {
|
||||||
|
//note: Using cursor pos as screen detector. Flawed.
|
||||||
|
QPoint cursorPos = QCursor::pos();
|
||||||
|
|
||||||
|
for (QScreen *screen : QGuiApplication::screens()) {
|
||||||
|
QRect screenRect = screen->geometry();
|
||||||
|
if (screenRect.contains(cursorPos)) {
|
||||||
|
return screen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QGuiApplication::primaryScreen();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,10 @@ public:
|
||||||
return baseStyle()->styleHint(hint, option, widget, returnData);
|
return baseStyle()->styleHint(hint, option, widget, returnData);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option,
|
QRect subControlRect(ComplexControl control,
|
||||||
SubControl subControl, const QWidget *widget) const {
|
const QStyleOptionComplex *option,
|
||||||
|
SubControl subControl,
|
||||||
|
const QWidget *widget) const {
|
||||||
QRect rect = QCommonStyle::subControlRect(CC_Slider, option, subControl, widget);
|
QRect rect = QCommonStyle::subControlRect(CC_Slider, option, subControl, widget);
|
||||||
|
|
||||||
switch (control) {
|
switch (control) {
|
||||||
|
|
@ -186,6 +188,51 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawControl(ControlElement element, const QStyleOption *opt,
|
||||||
|
QPainter *p, const QWidget *widget) const
|
||||||
|
{
|
||||||
|
switch(element) {
|
||||||
|
case CE_ExtendedCheckBox:
|
||||||
|
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
|
||||||
|
QStyleOptionButton subopt = *btn;
|
||||||
|
subopt.rect = subElementRect(SE_CheckBoxIndicator, btn, widget);
|
||||||
|
//proxy()->drawPrimitive(PE_IndicatorCheckBox, &subopt, p, widget);
|
||||||
|
subopt.rect = subElementRect(SE_CheckBoxContents, btn, widget);
|
||||||
|
|
||||||
|
//proxy()->drawControl(CE_CheckBoxLabel, &subopt, p, widget);
|
||||||
|
int alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
|
|
||||||
|
if (!proxy()->styleHint(SH_UnderlineShortcut, btn, widget))
|
||||||
|
alignment |= Qt::TextHideMnemonic;
|
||||||
|
QPixmap pix;
|
||||||
|
QRect textRect = btn->rect;
|
||||||
|
if (!btn->icon.isNull()) {
|
||||||
|
pix = btn->icon.pixmap(btn->iconSize, StylingHelper::getCurrentScreen()->devicePixelRatio(),
|
||||||
|
QIcon::Mode::Normal, btn->state & State_On ? QIcon::On : QIcon::Off);
|
||||||
|
proxy()->drawItemPixmap(p, btn->rect, alignment, pix);
|
||||||
|
if (btn->direction == Qt::RightToLeft)
|
||||||
|
textRect.setRight(textRect.right() - btn->iconSize.width() - 4);
|
||||||
|
else
|
||||||
|
textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);
|
||||||
|
}
|
||||||
|
if (!btn->text.isEmpty()){
|
||||||
|
proxy()->drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,
|
||||||
|
btn->palette, btn->state & State_Enabled, btn->text, QPalette::WindowText);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if (btn->state & State_HasFocus) {
|
||||||
|
QStyleOptionFocusRect fropt;
|
||||||
|
fropt.QStyleOption::operator=(*btn);
|
||||||
|
fropt.rect = subElementRect(SE_CheckBoxFocusRect, btn, widget);
|
||||||
|
proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
baseStyle()->drawControl(element, opt, p, widget);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *option,
|
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *option,
|
||||||
QPainter *painter, const QWidget *widget) const {
|
QPainter *painter, const QWidget *widget) const {
|
||||||
QColor outline;
|
QColor outline;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue