Buttons do resize now correctly with the window, prepared some custom rendering with the buttons

This commit is contained in:
mrbesen 2021-12-18 23:53:02 +01:00
parent 8d0ff7e918
commit a9ff7e1e6a
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
5 changed files with 78 additions and 62 deletions

View File

@ -29,6 +29,8 @@ public:
void setHighlighted(bool highlighted); void setHighlighted(bool highlighted);
void paintEvent(QPaintEvent *) override;
public slots: public slots:
void play(); void play();

View File

@ -183,7 +183,7 @@ void MainWindow::loadButtonsFromConfig() {
x += bc.width; x += bc.width;
} }
ui->gridLayout->setRowMinimumHeight(y, 60); //ui->gridLayout->setRowMinimumHeight(y, 60);
x = 0; x = 0;
y++; y++;
} }
@ -197,7 +197,7 @@ void MainWindow::loadButtonsFromConfig() {
((SoundButton*) item->widget())->setHighlighted(true); ((SoundButton*) item->widget())->setHighlighted(true);
} }
// ui->gridLayoutWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); // ui->gridLayout->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
} }
void MainWindow::reselectNext(std::function<void(uint8_t&,uint8_t&)> stepf) { void MainWindow::reselectNext(std::function<void(uint8_t&,uint8_t&)> stepf) {

View File

@ -140,7 +140,7 @@ void Sound::init() {
void Sound::backgroundThreadLoop() { void Sound::backgroundThreadLoop() {
while(threadShouldrun) { while(threadShouldrun) {
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::seconds(1));
cleanAllDecoders(); cleanAllDecoders();
} }
} }

View File

@ -1,5 +1,7 @@
#include "soundbutton.h" #include "soundbutton.h"
#include <QTextItem>
#include "sound.h" #include "sound.h"
#include <Log.h> #include <Log.h>
@ -12,10 +14,10 @@ SoundButton::SoundButton(const std::string& filename, const std::string& name_,
QString info = getInfo(); QString info = getInfo();
setText(info); setText(info);
setObjectName(QString::fromStdString("soundButton" + std::to_string(id))); setObjectName(QString::fromStdString("soundButton" + std::to_string(id)));
setMinimumHeight(50); setMinimumSize(QSize(80, 20));
setToolTip(info); setToolTip(info);
// button->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
QKeySequence seq(QString::fromStdString(keycombo)); QKeySequence seq(QString::fromStdString(keycombo));
globalShortcut = new QxtGlobalShortcut(seq); globalShortcut = new QxtGlobalShortcut(seq);
@ -74,6 +76,22 @@ void SoundButton::setHighlighted(bool highlighted) {
} }
} }
void SoundButton::paintEvent(QPaintEvent* event) {
QPushButton::paintEvent(event);
QString text = "";
// cancel if nothing to print
if(text.isEmpty())
return;
QPainter painter(this);
painter.setPen(QPen(Qt::white));
QPoint textPos(0, painter.fontMetrics().height());
textPos.rx() = width() - painter.fontMetrics().horizontalAdvance(text) - 6;
painter.drawText(textPos, text);
}
void SoundButton::play() { void SoundButton::play() {
if(disabled) return; if(disabled) return;

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>824</width> <width>615</width>
<height>675</height> <height>639</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -15,72 +15,68 @@
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<widget class="QWidget" name="gridLayoutWidget"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="geometry"> <property name="sizeConstraint">
<rect> <enum>QLayout::SetNoConstraint</enum>
<x>10</x>
<y>40</y>
<width>791</width>
<height>561</height>
</rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout" rowminimumheight="0"> <item>
<property name="sizeConstraint"> <layout class="QHBoxLayout" name="topRow">
<enum>QLayout::SetMaximumSize</enum> <item>
</property> <widget class="QPushButton" name="reloadButton">
</layout> <property name="text">
</widget> <string>reload Config</string>
<widget class="QPushButton" name="reloadButton"> </property>
<property name="geometry"> </widget>
<rect> </item>
<x>10</x> <item>
<y>10</y> <widget class="QPushButton" name="stopButton">
<width>141</width> <property name="text">
<height>27</height> <string>Stop</string>
</rect> </property>
</property> </widget>
<property name="text"> </item>
<string>reload Config</string> <item>
</property> <spacer name="horizontalSpacer">
</widget> <property name="orientation">
<widget class="QPushButton" name="stopButton"> <enum>Qt::Horizontal</enum>
<property name="geometry"> </property>
<rect> <property name="sizeHint" stdset="0">
<x>160</x> <size>
<y>10</y> <width>40</width>
<width>100</width> <height>20</height>
<height>27</height> </size>
</rect> </property>
</property> </spacer>
<property name="text"> </item>
<string>Stop</string> <item>
</property> <widget class="QCheckBox" name="allwaysOnTop">
</widget> <property name="text">
<widget class="QCheckBox" name="allwaysOnTop"> <string>AllwaysOnTop</string>
<property name="geometry"> </property>
<rect> </widget>
<x>660</x> </item>
<y>10</y> </layout>
<width>141</width> </item>
<height>25</height> <item>
</rect> <layout class="QGridLayout" name="gridLayout" rowminimumheight="0">
</property> <property name="sizeConstraint">
<property name="text"> <enum>QLayout::SetMinimumSize</enum>
<string>AllwaysOnTop</string> </property>
</property> </layout>
</widget> </item>
</layout>
</widget> </widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>824</width> <width>615</width>
<height>24</height> <height>24</height>
</rect> </rect>
</property> </property>