Changeset View
Changeset View
Standalone View
Standalone View
statuslabel.cpp
Show All 19 Lines | |||||
20 | #include <KSqueezedTextLabel> | 20 | #include <KSqueezedTextLabel> | ||
21 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
22 | #include <KFormat> | 22 | #include <KFormat> | ||
23 | 23 | | |||
24 | #include <QAction> | 24 | #include <QAction> | ||
25 | #include <QMouseEvent> | 25 | #include <QMouseEvent> | ||
26 | #include <QLabel> | 26 | #include <QLabel> | ||
27 | #include <QFrame> | 27 | #include <QFrame> | ||
28 | #include <QHBoxLayout> | | |||
29 | #include <QEvent> | 28 | #include <QEvent> | ||
30 | #include <QPushButton> | 29 | #include <QPushButton> | ||
30 | #include <QStatusBar> | ||||
31 | 31 | | |||
32 | #include "filehandle.h" | 32 | #include "filehandle.h" | ||
33 | #include "playlistinterface.h" | 33 | #include "playlistinterface.h" | ||
34 | #include "actioncollection.h" | 34 | #include "actioncollection.h" | ||
35 | #include "playermanager.h" | 35 | #include "playermanager.h" | ||
36 | #include "tag.h" | 36 | #include "tag.h" | ||
37 | #include "juk_debug.h" | 37 | #include "juk_debug.h" | ||
38 | 38 | | |||
39 | using namespace ActionCollection; | 39 | using namespace ActionCollection; | ||
40 | 40 | | |||
41 | //////////////////////////////////////////////////////////////////////////////// | 41 | //////////////////////////////////////////////////////////////////////////////// | ||
42 | // static helpers | 42 | // static helpers | ||
43 | //////////////////////////////////////////////////////////////////////////////// | 43 | //////////////////////////////////////////////////////////////////////////////// | ||
44 | 44 | | |||
45 | static QString formatTime(qint64 milliseconds) | 45 | static QString formatTime(qint64 milliseconds) | ||
46 | { | 46 | { | ||
47 | static const KFormat fmt; | 47 | static const KFormat fmt; | ||
48 | return fmt.formatDuration(milliseconds); | 48 | return fmt.formatDuration(milliseconds); | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | //////////////////////////////////////////////////////////////////////////////// | 51 | //////////////////////////////////////////////////////////////////////////////// | ||
52 | // public methods | 52 | // public methods | ||
53 | //////////////////////////////////////////////////////////////////////////////// | 53 | //////////////////////////////////////////////////////////////////////////////// | ||
54 | 54 | | |||
55 | StatusLabel::StatusLabel(const PlaylistInterface ¤tPlaylist, QWidget *parent) : | 55 | StatusLabel::StatusLabel(const PlaylistInterface ¤tPlaylist, QStatusBar *parent) : | ||
56 | QWidget(parent) | 56 | QWidget(parent) | ||
57 | { | 57 | { | ||
58 | auto hboxLayout = new QHBoxLayout(this); | 58 | m_playlistLabel = new KSqueezedTextLabel(this); | ||
59 | 59 | m_playlistLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::Label)); | |||
mpyne: I like it, but I'd rather change the `QWidget *parent` parameter to be a `QStatusBar… | |||||
60 | QFrame *trackAndPlaylist = new QFrame(this); | | |||
61 | hboxLayout->addWidget(trackAndPlaylist); | | |||
62 | trackAndPlaylist->setFrameStyle(QFrame::Box | QFrame::Sunken); | | |||
63 | trackAndPlaylist->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | | |||
64 | | ||||
65 | // Make sure that we have enough of a margin to suffice for the borders, | | |||
66 | // hence the "lineWidth() * 2" | | |||
67 | QHBoxLayout *trackAndPlaylistLayout = new QHBoxLayout(trackAndPlaylist); | | |||
68 | trackAndPlaylistLayout->setMargin(trackAndPlaylist->lineWidth() * 2); | | |||
69 | trackAndPlaylistLayout->setSpacing(5); | | |||
70 | trackAndPlaylistLayout->setObjectName(QLatin1String("trackAndPlaylistLayout")); | | |||
71 | trackAndPlaylistLayout->addSpacing(5); | | |||
72 | | ||||
73 | m_playlistLabel = new KSqueezedTextLabel(trackAndPlaylist); | | |||
74 | trackAndPlaylistLayout->addWidget(m_playlistLabel); | | |||
75 | m_playlistLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | | |||
76 | m_playlistLabel->setTextFormat(Qt::PlainText); | 60 | m_playlistLabel->setTextFormat(Qt::PlainText); | ||
77 | m_playlistLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | 61 | m_playlistLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | ||
62 | parent->addWidget(m_playlistLabel, 1); | ||||
78 | 63 | | |||
79 | m_trackLabel = new KSqueezedTextLabel(trackAndPlaylist); | 64 | m_trackLabel = new QLabel(this); | ||
80 | trackAndPlaylistLayout->addWidget(m_trackLabel); | | |||
81 | m_trackLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | 65 | m_trackLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | ||
82 | m_trackLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | | |||
83 | m_trackLabel->setTextFormat(Qt::PlainText); | 66 | m_trackLabel->setTextFormat(Qt::PlainText); | ||
84 | 67 | parent->addPermanentWidget(m_trackLabel); | |||
85 | trackAndPlaylistLayout->addSpacing(5); | | |||
86 | 68 | | |||
87 | m_itemTimeLabel = new QLabel(this); | 69 | m_itemTimeLabel = new QLabel(this); | ||
88 | hboxLayout->addWidget(m_itemTimeLabel); | | |||
89 | QFontMetrics fontMetrics(font()); | 70 | QFontMetrics fontMetrics(font()); | ||
90 | m_itemTimeLabel->setAlignment(Qt::AlignCenter); | 71 | m_itemTimeLabel->setAlignment(Qt::AlignCenter); | ||
91 | m_itemTimeLabel->setMinimumWidth(fontMetrics.boundingRect("000:00 / 000:00").width()); | 72 | m_itemTimeLabel->setMinimumWidth(fontMetrics.boundingRect("000:00 / 000:00").width()); | ||
92 | m_itemTimeLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | 73 | m_itemTimeLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | ||
93 | m_itemTimeLabel->setFrameStyle(QFrame::Box | QFrame::Sunken); | 74 | m_itemTimeLabel->setFrameStyle(QFrame::Box | QFrame::Sunken); | ||
94 | m_itemTimeLabel->installEventFilter(this); | 75 | m_itemTimeLabel->installEventFilter(this); | ||
76 | parent->addPermanentWidget(m_itemTimeLabel); | ||||
95 | 77 | | |||
96 | setItemTotalTime(0); | 78 | setItemTotalTime(0); | ||
97 | setItemCurrentTime(0); | 79 | setItemCurrentTime(0); | ||
98 | 80 | | |||
99 | auto jumpBox = new QFrame(this); | 81 | QPushButton *jumpButton = new QPushButton(this); | ||
100 | hboxLayout->addWidget(jumpBox); | | |||
101 | jumpBox->setFrameStyle(QFrame::Box | QFrame::Sunken); | | |||
102 | jumpBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); | | |||
103 | | ||||
104 | auto jumpBoxHLayout = new QHBoxLayout(jumpBox); | | |||
105 | | ||||
106 | QPushButton *jumpButton = new QPushButton(jumpBox); | | |||
107 | jumpBoxHLayout->addWidget(jumpButton); | | |||
108 | jumpButton->setIcon(SmallIcon("go-up")); | 82 | jumpButton->setIcon(SmallIcon("go-up")); | ||
109 | jumpButton->setFlat(true); | 83 | jumpButton->setFlat(true); | ||
110 | 84 | | |||
111 | jumpButton->setToolTip(i18n("Jump to the currently playing item")); | 85 | jumpButton->setToolTip(i18n("Jump to the currently playing item")); | ||
112 | connect(jumpButton, &QPushButton::clicked, action("showPlaying"), &QAction::trigger); | 86 | connect(jumpButton, &QPushButton::clicked, action("showPlaying"), &QAction::trigger); | ||
113 | 87 | | |||
88 | parent->addPermanentWidget(jumpButton); | ||||
114 | installEventFilter(this); | 89 | installEventFilter(this); | ||
115 | 90 | | |||
116 | slotCurrentPlaylistHasChanged(currentPlaylist); | 91 | slotCurrentPlaylistHasChanged(currentPlaylist); | ||
117 | } | 92 | } | ||
118 | 93 | | |||
119 | void StatusLabel::slotPlayingItemHasChanged(const FileHandle &file) | 94 | void StatusLabel::slotPlayingItemHasChanged(const FileHandle &file) | ||
120 | { | 95 | { | ||
121 | const Tag *tag = file.tag(); | 96 | const Tag *tag = file.tag(); | ||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
I like it, but I'd rather change the QWidget *parent parameter to be a QStatusBar *statusBar than to have a static_cast here. JuK controls the type of this parameter so there's no need to leave it as a QWidget if it has to be something else.