Small ui improvements
This commit is contained in:
parent
887e14add9
commit
6eea5688a8
5 changed files with 467 additions and 360 deletions
|
|
@ -36,6 +36,7 @@ add_executable(${PROJECT_NAME}
|
|||
src/clickableslider.cpp
|
||||
${MusicGeneratorGUI_H}
|
||||
res/resources.qrc
|
||||
src/elidedlabel.h src/elidedlabel.cpp
|
||||
)
|
||||
|
||||
# UI file
|
||||
|
|
|
|||
|
|
@ -89,6 +89,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
ui->songListView->setCurrentIndex(firstIndex);
|
||||
}
|
||||
|
||||
ui->nowPlayingLabel->setText("Now Playing:");
|
||||
|
||||
currentSong = songModel->getSong(0);
|
||||
}
|
||||
|
||||
|
|
@ -426,7 +428,7 @@ void MainWindow::songGenerated(const SongItem& song)
|
|||
{
|
||||
generatedSongQueue.enqueue(song);
|
||||
}
|
||||
ui->statusLabel->setText("idle");
|
||||
ui->statusbar->showMessage("idle");
|
||||
|
||||
ensureSongsInQueue();
|
||||
}
|
||||
|
|
@ -530,7 +532,7 @@ void MainWindow::ensureSongsInQueue(bool enqeueCurrent)
|
|||
|
||||
isGeneratingNext = true;
|
||||
|
||||
ui->statusLabel->setText("Generateing: "+nextSong.caption);
|
||||
ui->statusbar->showMessage("Generateing: "+nextSong.caption);
|
||||
aceStepWorker->generateSong(nextSong, jsonTemplate,
|
||||
aceStepPath, qwen3ModelPath,
|
||||
textEncoderModelPath, ditModelPath,
|
||||
|
|
|
|||
|
|
@ -114,15 +114,18 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="nowPlayingLabel">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LayoutDirection::LeftToRight</enum>
|
||||
<widget class="ElidedLabel" name="nowPlayingLabel">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Now Playing:</string>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -241,13 +244,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
@ -351,6 +347,12 @@
|
|||
<extends>QWidget</extends>
|
||||
<header>src/clickableslider.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ElidedLabel</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>src/elidedlabel.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../res/resources.qrc"/>
|
||||
|
|
|
|||
70
src/elidedlabel.cpp
Normal file
70
src/elidedlabel.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#include "elidedlabel.h"
|
||||
|
||||
#include <QTextLayout>
|
||||
#include <QPainter>
|
||||
|
||||
ElidedLabel::ElidedLabel(const QString &text, QWidget *parent)
|
||||
: QFrame(parent)
|
||||
, elided(false)
|
||||
, content(text)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
ElidedLabel::ElidedLabel(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
, elided(false)
|
||||
, content("")
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
void ElidedLabel::setText(const QString &newText)
|
||||
{
|
||||
content = newText;
|
||||
update();
|
||||
}
|
||||
|
||||
void ElidedLabel::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QFrame::paintEvent(event);
|
||||
|
||||
QPainter painter(this);
|
||||
QFontMetrics fontMetrics = painter.fontMetrics();
|
||||
|
||||
bool didElide = false;
|
||||
int lineSpacing = fontMetrics.lineSpacing();
|
||||
int y = 0;
|
||||
|
||||
QTextLayout textLayout(content, painter.font());
|
||||
textLayout.beginLayout();
|
||||
forever {
|
||||
QTextLine line = textLayout.createLine();
|
||||
|
||||
if (!line.isValid())
|
||||
break;
|
||||
|
||||
line.setLineWidth(width());
|
||||
int nextLineY = y + lineSpacing;
|
||||
|
||||
if (height() >= nextLineY + lineSpacing) {
|
||||
line.draw(&painter, QPoint(0, y));
|
||||
y = nextLineY;
|
||||
//! [2]
|
||||
//! [3]
|
||||
} else {
|
||||
QString lastLine = content.mid(line.textStart());
|
||||
QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width());
|
||||
painter.drawText(QPoint(0, y + fontMetrics.ascent()), elidedLastLine);
|
||||
line = textLayout.createLine();
|
||||
didElide = line.isValid();
|
||||
break;
|
||||
}
|
||||
}
|
||||
textLayout.endLayout();
|
||||
|
||||
if (didElide != elided) {
|
||||
elided = didElide;
|
||||
emit elisionChanged(didElide);
|
||||
}
|
||||
}
|
||||
32
src/elidedlabel.h
Normal file
32
src/elidedlabel.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef ELIDEDLABEL_H
|
||||
#define ELIDEDLABEL_H
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
class ElidedLabel : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(bool isElided READ isElided)
|
||||
|
||||
public:
|
||||
explicit ElidedLabel(const QString &text, QWidget *parent = 0);
|
||||
explicit ElidedLabel(QWidget *parent = 0);
|
||||
|
||||
void setText(const QString &text);
|
||||
const QString & text() const { return content; }
|
||||
bool isElided() const { return elided; }
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
signals:
|
||||
void elisionChanged(bool elided);
|
||||
|
||||
private:
|
||||
bool elided;
|
||||
QString content;
|
||||
};
|
||||
|
||||
|
||||
#endif // ELIDEDLABEL_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue