basic cursor
This commit is contained in:
parent
425b0df19f
commit
94786b668f
|
@ -2,6 +2,7 @@
|
|||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <qlayoutitem.h>
|
||||
#include <vector>
|
||||
|
||||
#include "config.h"
|
||||
|
@ -38,6 +39,10 @@ private:
|
|||
void removeAllButtons();
|
||||
void loadButtonsFromConfig();
|
||||
|
||||
void selectCurrentButton();
|
||||
void unselectCurrentButton();
|
||||
QLayoutItem* findCurrentButton() const;
|
||||
|
||||
Ui::Soundboard *ui;
|
||||
std::vector<SoundButton*> soundbuttons;
|
||||
QxtGlobalShortcut* stopGlobal = nullptr;
|
||||
|
@ -48,6 +53,9 @@ private:
|
|||
QxtGlobalShortcut* right = nullptr;
|
||||
QxtGlobalShortcut* play = nullptr;
|
||||
|
||||
uint8_t xpos = 0;
|
||||
uint8_t ypos = 0;
|
||||
|
||||
Config config;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -30,7 +30,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::Soundb
|
|||
QObject::connect(left, SIGNAL( activated() ), this, SLOT( moveLeft() ));
|
||||
QObject::connect(right, SIGNAL( activated() ), this, SLOT( moveRight() ));
|
||||
QObject::connect(play, SIGNAL( activated() ), this, SLOT( playCurrent() ));
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
|
@ -72,22 +71,54 @@ void MainWindow::stop() {
|
|||
|
||||
void MainWindow::moveUp() {
|
||||
Log::debug << "up";
|
||||
unselectCurrentButton();
|
||||
ypos--;
|
||||
if(ypos >= ui->gridLayout->rowCount()) {
|
||||
ypos = ui->gridLayout->rowCount()-1;
|
||||
}
|
||||
selectCurrentButton();
|
||||
}
|
||||
|
||||
void MainWindow::moveDown() {
|
||||
Log::debug << "down";
|
||||
unselectCurrentButton();
|
||||
ypos++;
|
||||
if(ypos >= ui->gridLayout->rowCount()) {
|
||||
ypos = ui->gridLayout->rowCount()-1;
|
||||
}
|
||||
selectCurrentButton();
|
||||
}
|
||||
|
||||
void MainWindow::moveLeft() {
|
||||
Log::debug << "left";
|
||||
unselectCurrentButton();
|
||||
xpos--;
|
||||
if(xpos >= ui->gridLayout->columnCount()) {
|
||||
xpos = ui->gridLayout->columnCount()-1;
|
||||
}
|
||||
selectCurrentButton();
|
||||
}
|
||||
|
||||
void MainWindow::moveRight() {
|
||||
Log::debug << "right";
|
||||
unselectCurrentButton();
|
||||
xpos++;
|
||||
if(xpos >= ui->gridLayout->columnCount()) {
|
||||
xpos = ui->gridLayout->columnCount()-1;
|
||||
}
|
||||
selectCurrentButton();
|
||||
}
|
||||
|
||||
void MainWindow::playCurrent() {
|
||||
Log::debug << "play";
|
||||
|
||||
QLayoutItem* item = findCurrentButton();
|
||||
if(item) {
|
||||
if(item->widget()) {
|
||||
QPushButton* button = (QPushButton*) item->widget();
|
||||
button->click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadSoundFromConfig() {
|
||||
|
@ -147,5 +178,49 @@ void MainWindow::loadButtonsFromConfig() {
|
|||
y++;
|
||||
}
|
||||
|
||||
xpos = 0;
|
||||
ypos = 0;
|
||||
|
||||
// ui->gridLayoutWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
|
||||
}
|
||||
|
||||
void MainWindow::selectCurrentButton() {
|
||||
QLayoutItem* item = findCurrentButton();
|
||||
if(item) {
|
||||
if(item->widget()) {
|
||||
QPushButton* button = (QPushButton*) item->widget();
|
||||
button->setText(">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::unselectCurrentButton() {
|
||||
QLayoutItem* item = findCurrentButton();
|
||||
if(item) {
|
||||
if(item->widget()) {
|
||||
QPushButton* button = (QPushButton*) item->widget();
|
||||
button->setText(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QLayoutItem* MainWindow::findCurrentButton() const {
|
||||
QLayoutItem* lastitem = nullptr;
|
||||
int8_t rstep = -1;
|
||||
for(uint8_t step = 0; step < ui->gridLayout->columnCount() && rstep < xpos; ++step) {
|
||||
Log::info << "check: " << ypos << " " << step;
|
||||
|
||||
QLayoutItem* item = ui->gridLayout->itemAtPosition(ypos, step);
|
||||
if(lastitem == item) continue;
|
||||
|
||||
rstep++;
|
||||
lastitem = item;
|
||||
}
|
||||
|
||||
if(lastitem != nullptr && rstep == xpos) {
|
||||
return lastitem;
|
||||
}
|
||||
|
||||
Log::debug << "current button is null";
|
||||
return nullptr;
|
||||
}
|
Loading…
Reference in New Issue