mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 11:19:18 +01:00
Indicate which column alignment action is currently set on each column in the menu.
This commit is contained in:
parent
63fdf11cd8
commit
efce2498ca
@ -23,8 +23,10 @@
|
||||
#include <QMenu>
|
||||
#include <QSignalMapper>
|
||||
|
||||
PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, QWidget* parent)
|
||||
PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, PlaylistView* view,
|
||||
QWidget* parent)
|
||||
: StretchHeaderView(orientation, parent),
|
||||
view_(view),
|
||||
menu_(new QMenu(this)),
|
||||
show_mapper_(new QSignalMapper(this))
|
||||
{
|
||||
@ -32,9 +34,18 @@ PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, QWidget* parent)
|
||||
stretch_action_ = menu_->addAction(tr("&Stretch columns to fit window"), this, SLOT(ToggleStretchEnabled()));
|
||||
menu_->addSeparator();
|
||||
|
||||
QMenu* align_menu = new QMenu(tr("&Align text"), this); align_left_action_ = align_menu->addAction(tr("&Left"), this, SLOT(AlignCurrentLeft()));
|
||||
align_center_action_ = align_menu->addAction(tr("&Center"), this, SLOT(AlignCurrentCenter()));
|
||||
align_right_action_ = align_menu->addAction(tr("&Right"), this, SLOT(AlignCurrentRight()));
|
||||
QMenu* align_menu = new QMenu(tr("&Align text"), this);
|
||||
QActionGroup* align_group = new QActionGroup(this);
|
||||
align_left_action_ = new QAction(tr("&Left"), align_group);
|
||||
align_center_action_ = new QAction(tr("&Center"), align_group);
|
||||
align_right_action_ = new QAction(tr("&Right"), align_group);
|
||||
|
||||
align_left_action_->setCheckable(true);
|
||||
align_center_action_->setCheckable(true);
|
||||
align_right_action_->setCheckable(true);
|
||||
align_menu->addActions(align_group->actions());
|
||||
|
||||
connect(align_group, SIGNAL(triggered(QAction*)), SLOT(SetColumnAlignment(QAction*)));
|
||||
|
||||
menu_->addMenu(align_menu);
|
||||
menu_->addSeparator();
|
||||
@ -49,14 +60,19 @@ PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, QWidget* parent)
|
||||
void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) {
|
||||
menu_section_ = logicalIndexAt(e->pos());
|
||||
|
||||
if (menu_section_ == -1 || (
|
||||
menu_section_ == logicalIndex(0) && logicalIndex(1) == -1))
|
||||
if (menu_section_ == -1 ||
|
||||
(menu_section_ == logicalIndex(0) && logicalIndex(1) == -1))
|
||||
hide_action_->setVisible(false);
|
||||
else {
|
||||
hide_action_->setVisible(true);
|
||||
|
||||
QString title(model()->headerData(menu_section_, Qt::Horizontal).toString());
|
||||
hide_action_->setText(tr("&Hide %1").arg(title));
|
||||
|
||||
Qt::Alignment alignment = view_->column_alignment(menu_section_);
|
||||
if (alignment & Qt::AlignLeft) align_left_action_->setChecked(true);
|
||||
else if (alignment & Qt::AlignHCenter) align_center_action_->setChecked(true);
|
||||
else if (alignment & Qt::AlignRight) align_right_action_->setChecked(true);
|
||||
}
|
||||
|
||||
qDeleteAll(show_actions_);
|
||||
@ -86,19 +102,14 @@ void PlaylistHeader::HideCurrent() {
|
||||
SetSectionHidden(menu_section_, true);
|
||||
}
|
||||
|
||||
void PlaylistHeader::AlignCurrentLeft() {
|
||||
static_cast<PlaylistView*>(parent())->SetColumnAlignment(
|
||||
menu_section_, Qt::AlignLeft | Qt::AlignVCenter);
|
||||
}
|
||||
void PlaylistHeader::SetColumnAlignment(QAction* action) {
|
||||
Qt::Alignment alignment = Qt::AlignVCenter;
|
||||
|
||||
void PlaylistHeader::AlignCurrentCenter() {
|
||||
static_cast<PlaylistView*>(parent())->SetColumnAlignment(
|
||||
menu_section_, Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
}
|
||||
if (action == align_left_action_) alignment |= Qt::AlignLeft;
|
||||
if (action == align_center_action_) alignment |= Qt::AlignHCenter;
|
||||
if (action == align_right_action_) alignment |= Qt::AlignRight;
|
||||
|
||||
void PlaylistHeader::AlignCurrentRight() {
|
||||
static_cast<PlaylistView*>(parent())->SetColumnAlignment(
|
||||
menu_section_, Qt::AlignRight | Qt::AlignVCenter);
|
||||
view_->SetColumnAlignment(menu_section_, alignment);
|
||||
}
|
||||
|
||||
void PlaylistHeader::ToggleVisible(int section) {
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "widgets/stretchheaderview.h"
|
||||
|
||||
class PlaylistView;
|
||||
|
||||
class QMenu;
|
||||
class QSignalMapper;
|
||||
|
||||
@ -27,7 +29,8 @@ class PlaylistHeader : public StretchHeaderView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlaylistHeader(Qt::Orientation orientation, QWidget* parent = 0);
|
||||
PlaylistHeader(Qt::Orientation orientation, PlaylistView* view,
|
||||
QWidget* parent = 0);
|
||||
|
||||
// QWidget
|
||||
void contextMenuEvent(QContextMenuEvent* e);
|
||||
@ -39,15 +42,15 @@ class PlaylistHeader : public StretchHeaderView {
|
||||
|
||||
private slots:
|
||||
void HideCurrent();
|
||||
void AlignCurrentLeft();
|
||||
void AlignCurrentCenter();
|
||||
void AlignCurrentRight();
|
||||
void ToggleVisible(int section);
|
||||
void SetColumnAlignment(QAction* action);
|
||||
|
||||
private:
|
||||
void AddColumnAction(int index);
|
||||
|
||||
private:
|
||||
PlaylistView* view_;
|
||||
|
||||
int menu_section_;
|
||||
QMenu* menu_;
|
||||
QAction* hide_action_;
|
||||
|
@ -85,7 +85,7 @@ PlaylistView::PlaylistView(QWidget *parent)
|
||||
: QTreeView(parent),
|
||||
style_(new PlaylistProxyStyle(style())),
|
||||
playlist_(NULL),
|
||||
header_(new PlaylistHeader(Qt::Horizontal, this)),
|
||||
header_(new PlaylistHeader(Qt::Horizontal, this, this)),
|
||||
setting_initial_header_layout_(false),
|
||||
upgrading_from_qheaderview_(false),
|
||||
read_only_settings_(true),
|
||||
@ -985,3 +985,7 @@ void PlaylistView::SetColumnAlignment(int section, Qt::Alignment alignment) {
|
||||
emit ColumnAlignmentChanged(column_alignment_);
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
Qt::Alignment PlaylistView::column_alignment(int section) const {
|
||||
return column_alignment_.value(section, Qt::AlignLeft | Qt::AlignVCenter);
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ class PlaylistView : public QTreeView {
|
||||
|
||||
Playlist* playlist() const { return playlist_; }
|
||||
bool background_enabled() const { return background_enabled_; }
|
||||
Qt::Alignment column_alignment(int section) const;
|
||||
|
||||
// QTreeView
|
||||
void drawTree(QPainter* painter, const QRegion& region) const;
|
||||
|
@ -125,11 +125,11 @@ msgstr ""
|
||||
msgid "%n remaining"
|
||||
msgstr ""
|
||||
|
||||
#: playlist/playlistheader.cpp:35
|
||||
#: playlist/playlistheader.cpp:37
|
||||
msgid "&Align text"
|
||||
msgstr ""
|
||||
|
||||
#: playlist/playlistheader.cpp:36
|
||||
#: playlist/playlistheader.cpp:40
|
||||
msgid "&Center"
|
||||
msgstr ""
|
||||
|
||||
@ -145,16 +145,16 @@ msgstr ""
|
||||
msgid "&Help"
|
||||
msgstr ""
|
||||
|
||||
#: playlist/playlistheader.cpp:59
|
||||
#: playlist/playlistheader.cpp:70
|
||||
#, qt-format
|
||||
msgid "&Hide %1"
|
||||
msgstr ""
|
||||
|
||||
#: playlist/playlistheader.cpp:31
|
||||
#: playlist/playlistheader.cpp:33
|
||||
msgid "&Hide..."
|
||||
msgstr ""
|
||||
|
||||
#: playlist/playlistheader.cpp:35
|
||||
#: playlist/playlistheader.cpp:39
|
||||
msgid "&Left"
|
||||
msgstr ""
|
||||
|
||||
@ -178,7 +178,7 @@ msgstr ""
|
||||
msgid "&Repeat mode"
|
||||
msgstr ""
|
||||
|
||||
#: playlist/playlistheader.cpp:37
|
||||
#: playlist/playlistheader.cpp:41
|
||||
msgid "&Right"
|
||||
msgstr ""
|
||||
|
||||
@ -186,7 +186,7 @@ msgstr ""
|
||||
msgid "&Shuffle mode"
|
||||
msgstr ""
|
||||
|
||||
#: playlist/playlistheader.cpp:32
|
||||
#: playlist/playlistheader.cpp:34
|
||||
msgid "&Stretch columns to fit window"
|
||||
msgstr ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user