diff --git a/include/soundbutton.h b/include/soundbutton.h index 3f5be3a..a491456 100644 --- a/include/soundbutton.h +++ b/include/soundbutton.h @@ -29,6 +29,8 @@ public: void setHighlighted(bool highlighted); + void paintEvent(QPaintEvent *) override; + public slots: void play(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 84834de..0ce8e77 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -183,7 +183,7 @@ void MainWindow::loadButtonsFromConfig() { x += bc.width; } - ui->gridLayout->setRowMinimumHeight(y, 60); + //ui->gridLayout->setRowMinimumHeight(y, 60); x = 0; y++; } @@ -197,7 +197,7 @@ void MainWindow::loadButtonsFromConfig() { ((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 stepf) { diff --git a/src/sound.cpp b/src/sound.cpp index 3da0ec7..84e0992 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -140,7 +140,7 @@ void Sound::init() { void Sound::backgroundThreadLoop() { while(threadShouldrun) { - std::this_thread::sleep_for(std::chrono::milliseconds(50)); + std::this_thread::sleep_for(std::chrono::seconds(1)); cleanAllDecoders(); } } diff --git a/src/soundbutton.cpp b/src/soundbutton.cpp index 65844d3..d2b7331 100644 --- a/src/soundbutton.cpp +++ b/src/soundbutton.cpp @@ -1,5 +1,7 @@ #include "soundbutton.h" +#include + #include "sound.h" #include @@ -12,10 +14,10 @@ SoundButton::SoundButton(const std::string& filename, const std::string& name_, QString info = getInfo(); setText(info); setObjectName(QString::fromStdString("soundButton" + std::to_string(id))); - setMinimumHeight(50); + setMinimumSize(QSize(80, 20)); setToolTip(info); -// button->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); + setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); QKeySequence seq(QString::fromStdString(keycombo)); 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() { if(disabled) return; diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index ea81ff1..f95ca9e 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 824 - 675 + 615 + 639 @@ -15,72 +15,68 @@ - + 0 0 - - - - 10 - 40 - 791 - 561 - + + + QLayout::SetNoConstraint - - - QLayout::SetMaximumSize - - - - - - - 10 - 10 - 141 - 27 - - - - reload Config - - - - - - 160 - 10 - 100 - 27 - - - - Stop - - - - - - 660 - 10 - 141 - 25 - - - - AllwaysOnTop - - + + + + + + reload Config + + + + + + + Stop + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + AllwaysOnTop + + + + + + + + + QLayout::SetMinimumSize + + + + 0 0 - 824 + 615 24