parent
d870115467
commit
9bd728889b
@ -62,10 +62,11 @@ PlaylistTabBar::PlaylistTabBar(QWidget *parent)
|
|||||||
manager_(nullptr),
|
manager_(nullptr),
|
||||||
menu_(new QMenu(this)),
|
menu_(new QMenu(this)),
|
||||||
menu_index_(-1),
|
menu_index_(-1),
|
||||||
new_(nullptr),
|
action_star_(nullptr),
|
||||||
rename_(nullptr),
|
action_close_(nullptr),
|
||||||
close_(nullptr),
|
action_rename_(nullptr),
|
||||||
save_(nullptr),
|
action_save_(nullptr),
|
||||||
|
action_new_(nullptr),
|
||||||
drag_hover_tab_(0),
|
drag_hover_tab_(0),
|
||||||
suppress_current_changed_(false),
|
suppress_current_changed_(false),
|
||||||
initialized_(false),
|
initialized_(false),
|
||||||
@ -76,9 +77,10 @@ PlaylistTabBar::PlaylistTabBar(QWidget *parent)
|
|||||||
setUsesScrollButtons(true);
|
setUsesScrollButtons(true);
|
||||||
setTabsClosable(true);
|
setTabsClosable(true);
|
||||||
|
|
||||||
close_ = menu_->addAction(IconLoader::Load("list-remove"), tr("Close playlist"), this, &PlaylistTabBar::CloseSlot);
|
action_star_ = menu_->addAction(IconLoader::Load("star"), tr("Star playlist"), this, &PlaylistTabBar::StarSlot);
|
||||||
rename_ = menu_->addAction(IconLoader::Load("edit-rename"), tr("Rename playlist..."), this, &PlaylistTabBar::RenameSlot);
|
action_close_ = menu_->addAction(IconLoader::Load("list-remove"), tr("Close playlist"), this, &PlaylistTabBar::CloseSlot);
|
||||||
save_ = menu_->addAction(IconLoader::Load("document-save"), tr("Save playlist..."), this, &PlaylistTabBar::SaveSlot);
|
action_rename_ = menu_->addAction(IconLoader::Load("edit-rename"), tr("Rename playlist..."), this, &PlaylistTabBar::RenameSlot);
|
||||||
|
action_save_ = menu_->addAction(IconLoader::Load("document-save"), tr("Save playlist..."), this, &PlaylistTabBar::SaveSlot);
|
||||||
menu_->addSeparator();
|
menu_->addSeparator();
|
||||||
|
|
||||||
rename_editor_->setVisible(false);
|
rename_editor_->setVisible(false);
|
||||||
@ -97,7 +99,7 @@ void PlaylistTabBar::SetActions(QAction *new_playlist, QAction *load_playlist) {
|
|||||||
menu_->insertAction(nullptr, new_playlist);
|
menu_->insertAction(nullptr, new_playlist);
|
||||||
menu_->insertAction(nullptr, load_playlist);
|
menu_->insertAction(nullptr, load_playlist);
|
||||||
|
|
||||||
new_ = new_playlist;
|
action_new_ = new_playlist;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,9 +128,9 @@ void PlaylistTabBar::contextMenuEvent(QContextMenuEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu_index_ = tabAt(e->pos());
|
menu_index_ = tabAt(e->pos());
|
||||||
rename_->setEnabled(menu_index_ != -1);
|
action_rename_->setEnabled(menu_index_ != -1);
|
||||||
close_->setEnabled(menu_index_ != -1 && count() > 1);
|
action_close_->setEnabled(menu_index_ != -1 && count() > 1);
|
||||||
save_->setEnabled(menu_index_ != -1);
|
action_save_->setEnabled(menu_index_ != -1);
|
||||||
|
|
||||||
menu_->popup(e->globalPos());
|
menu_->popup(e->globalPos());
|
||||||
|
|
||||||
@ -153,7 +155,7 @@ void PlaylistTabBar::mouseDoubleClickEvent(QMouseEvent *e) {
|
|||||||
// Discard a double click with the middle button
|
// Discard a double click with the middle button
|
||||||
if (e->button() != Qt::MiddleButton) {
|
if (e->button() != Qt::MiddleButton) {
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
new_->activate(QAction::Trigger);
|
action_new_->activate(QAction::Trigger);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
menu_index_ = index;
|
menu_index_ = index;
|
||||||
@ -199,6 +201,17 @@ void PlaylistTabBar::HideEditor() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlaylistTabBar::StarSlot() {
|
||||||
|
|
||||||
|
if (menu_index_ == -1) return;
|
||||||
|
|
||||||
|
FavoriteWidget *favorite_widget = qobject_cast<FavoriteWidget*>(tabButton(menu_index_, QTabBar::LeftSide));
|
||||||
|
if (favorite_widget) {
|
||||||
|
favorite_widget->SetFavorite(!favorite_widget->IsFavorite());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void PlaylistTabBar::CloseSlot() {
|
void PlaylistTabBar::CloseSlot() {
|
||||||
|
|
||||||
if (menu_index_ == -1) return;
|
if (menu_index_ == -1) return;
|
||||||
|
@ -95,6 +95,7 @@ class PlaylistTabBar : public QTabBar {
|
|||||||
void RenameSlot();
|
void RenameSlot();
|
||||||
void RenameInline();
|
void RenameInline();
|
||||||
void HideEditor();
|
void HideEditor();
|
||||||
|
void StarSlot();
|
||||||
void CloseSlot();
|
void CloseSlot();
|
||||||
void CloseFromTabIndex(const int index);
|
void CloseFromTabIndex(const int index);
|
||||||
// Used when playlist's favorite flag isn't changed from the favorite widget (e.g. from the playlistlistcontainer): will update the favorite widget
|
// Used when playlist's favorite flag isn't changed from the favorite widget (e.g. from the playlistlistcontainer): will update the favorite widget
|
||||||
@ -109,10 +110,11 @@ class PlaylistTabBar : public QTabBar {
|
|||||||
|
|
||||||
QMenu *menu_;
|
QMenu *menu_;
|
||||||
int menu_index_;
|
int menu_index_;
|
||||||
QAction *new_;
|
QAction *action_star_;
|
||||||
QAction *rename_;
|
QAction *action_close_;
|
||||||
QAction *close_;
|
QAction *action_rename_;
|
||||||
QAction *save_;
|
QAction *action_save_;
|
||||||
|
QAction *action_new_;
|
||||||
|
|
||||||
QBasicTimer drag_hover_timer_;
|
QBasicTimer drag_hover_timer_;
|
||||||
int drag_hover_tab_;
|
int drag_hover_tab_;
|
||||||
|
@ -40,7 +40,7 @@ FavoriteWidget::FavoriteWidget(const int tab_index, const bool favorite, QWidget
|
|||||||
off_(":/icons/64x64/star-grey.png"),
|
off_(":/icons/64x64/star-grey.png"),
|
||||||
rect_(0, 0, kStarSize, kStarSize) {}
|
rect_(0, 0, kStarSize, kStarSize) {}
|
||||||
|
|
||||||
void FavoriteWidget::SetFavorite(bool favorite) {
|
void FavoriteWidget::SetFavorite(const bool favorite) {
|
||||||
|
|
||||||
if (favorite_ != favorite) {
|
if (favorite_ != favorite) {
|
||||||
favorite_ = favorite;
|
favorite_ = favorite;
|
||||||
|
@ -40,7 +40,8 @@ class FavoriteWidget : public QWidget {
|
|||||||
explicit FavoriteWidget(const int tab_index, const bool favorite = false, QWidget *parent = nullptr);
|
explicit FavoriteWidget(const int tab_index, const bool favorite = false, QWidget *parent = nullptr);
|
||||||
|
|
||||||
// Change the value if different from the current one and then update display and emit FavoriteStateChanged signal
|
// Change the value if different from the current one and then update display and emit FavoriteStateChanged signal
|
||||||
void SetFavorite(bool favorite);
|
bool IsFavorite() const { return favorite_; }
|
||||||
|
void SetFavorite(const bool favorite);
|
||||||
|
|
||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user