1
0
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:
David Sansome 2011-11-12 16:23:41 +00:00
parent 63fdf11cd8
commit efce2498ca
5 changed files with 48 additions and 29 deletions

View File

@ -23,8 +23,10 @@
#include <QMenu> #include <QMenu>
#include <QSignalMapper> #include <QSignalMapper>
PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, QWidget* parent) PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, PlaylistView* view,
QWidget* parent)
: StretchHeaderView(orientation, parent), : StretchHeaderView(orientation, parent),
view_(view),
menu_(new QMenu(this)), menu_(new QMenu(this)),
show_mapper_(new QSignalMapper(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())); stretch_action_ = menu_->addAction(tr("&Stretch columns to fit window"), this, SLOT(ToggleStretchEnabled()));
menu_->addSeparator(); menu_->addSeparator();
QMenu* align_menu = new QMenu(tr("&Align text"), this); align_left_action_ = align_menu->addAction(tr("&Left"), this, SLOT(AlignCurrentLeft())); QMenu* align_menu = new QMenu(tr("&Align text"), this);
align_center_action_ = align_menu->addAction(tr("&Center"), this, SLOT(AlignCurrentCenter())); QActionGroup* align_group = new QActionGroup(this);
align_right_action_ = align_menu->addAction(tr("&Right"), this, SLOT(AlignCurrentRight())); 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_->addMenu(align_menu);
menu_->addSeparator(); menu_->addSeparator();
@ -49,14 +60,19 @@ PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, QWidget* parent)
void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) { void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) {
menu_section_ = logicalIndexAt(e->pos()); menu_section_ = logicalIndexAt(e->pos());
if (menu_section_ == -1 || ( if (menu_section_ == -1 ||
menu_section_ == logicalIndex(0) && logicalIndex(1) == -1)) (menu_section_ == logicalIndex(0) && logicalIndex(1) == -1))
hide_action_->setVisible(false); hide_action_->setVisible(false);
else { else {
hide_action_->setVisible(true); hide_action_->setVisible(true);
QString title(model()->headerData(menu_section_, Qt::Horizontal).toString()); QString title(model()->headerData(menu_section_, Qt::Horizontal).toString());
hide_action_->setText(tr("&Hide %1").arg(title)); 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_); qDeleteAll(show_actions_);
@ -86,19 +102,14 @@ void PlaylistHeader::HideCurrent() {
SetSectionHidden(menu_section_, true); SetSectionHidden(menu_section_, true);
} }
void PlaylistHeader::AlignCurrentLeft() { void PlaylistHeader::SetColumnAlignment(QAction* action) {
static_cast<PlaylistView*>(parent())->SetColumnAlignment( Qt::Alignment alignment = Qt::AlignVCenter;
menu_section_, Qt::AlignLeft | Qt::AlignVCenter);
}
void PlaylistHeader::AlignCurrentCenter() { if (action == align_left_action_) alignment |= Qt::AlignLeft;
static_cast<PlaylistView*>(parent())->SetColumnAlignment( if (action == align_center_action_) alignment |= Qt::AlignHCenter;
menu_section_, Qt::AlignHCenter | Qt::AlignVCenter); if (action == align_right_action_) alignment |= Qt::AlignRight;
}
void PlaylistHeader::AlignCurrentRight() { view_->SetColumnAlignment(menu_section_, alignment);
static_cast<PlaylistView*>(parent())->SetColumnAlignment(
menu_section_, Qt::AlignRight | Qt::AlignVCenter);
} }
void PlaylistHeader::ToggleVisible(int section) { void PlaylistHeader::ToggleVisible(int section) {

View File

@ -20,6 +20,8 @@
#include "widgets/stretchheaderview.h" #include "widgets/stretchheaderview.h"
class PlaylistView;
class QMenu; class QMenu;
class QSignalMapper; class QSignalMapper;
@ -27,7 +29,8 @@ class PlaylistHeader : public StretchHeaderView {
Q_OBJECT Q_OBJECT
public: public:
PlaylistHeader(Qt::Orientation orientation, QWidget* parent = 0); PlaylistHeader(Qt::Orientation orientation, PlaylistView* view,
QWidget* parent = 0);
// QWidget // QWidget
void contextMenuEvent(QContextMenuEvent* e); void contextMenuEvent(QContextMenuEvent* e);
@ -39,15 +42,15 @@ class PlaylistHeader : public StretchHeaderView {
private slots: private slots:
void HideCurrent(); void HideCurrent();
void AlignCurrentLeft();
void AlignCurrentCenter();
void AlignCurrentRight();
void ToggleVisible(int section); void ToggleVisible(int section);
void SetColumnAlignment(QAction* action);
private: private:
void AddColumnAction(int index); void AddColumnAction(int index);
private: private:
PlaylistView* view_;
int menu_section_; int menu_section_;
QMenu* menu_; QMenu* menu_;
QAction* hide_action_; QAction* hide_action_;

View File

@ -85,7 +85,7 @@ PlaylistView::PlaylistView(QWidget *parent)
: QTreeView(parent), : QTreeView(parent),
style_(new PlaylistProxyStyle(style())), style_(new PlaylistProxyStyle(style())),
playlist_(NULL), playlist_(NULL),
header_(new PlaylistHeader(Qt::Horizontal, this)), header_(new PlaylistHeader(Qt::Horizontal, this, this)),
setting_initial_header_layout_(false), setting_initial_header_layout_(false),
upgrading_from_qheaderview_(false), upgrading_from_qheaderview_(false),
read_only_settings_(true), read_only_settings_(true),
@ -985,3 +985,7 @@ void PlaylistView::SetColumnAlignment(int section, Qt::Alignment alignment) {
emit ColumnAlignmentChanged(column_alignment_); emit ColumnAlignmentChanged(column_alignment_);
SaveSettings(); SaveSettings();
} }
Qt::Alignment PlaylistView::column_alignment(int section) const {
return column_alignment_.value(section, Qt::AlignLeft | Qt::AlignVCenter);
}

View File

@ -75,6 +75,7 @@ class PlaylistView : public QTreeView {
Playlist* playlist() const { return playlist_; } Playlist* playlist() const { return playlist_; }
bool background_enabled() const { return background_enabled_; } bool background_enabled() const { return background_enabled_; }
Qt::Alignment column_alignment(int section) const;
// QTreeView // QTreeView
void drawTree(QPainter* painter, const QRegion& region) const; void drawTree(QPainter* painter, const QRegion& region) const;

View File

@ -125,11 +125,11 @@ msgstr ""
msgid "%n remaining" msgid "%n remaining"
msgstr "" msgstr ""
#: playlist/playlistheader.cpp:35 #: playlist/playlistheader.cpp:37
msgid "&Align text" msgid "&Align text"
msgstr "" msgstr ""
#: playlist/playlistheader.cpp:36 #: playlist/playlistheader.cpp:40
msgid "&Center" msgid "&Center"
msgstr "" msgstr ""
@ -145,16 +145,16 @@ msgstr ""
msgid "&Help" msgid "&Help"
msgstr "" msgstr ""
#: playlist/playlistheader.cpp:59 #: playlist/playlistheader.cpp:70
#, qt-format #, qt-format
msgid "&Hide %1" msgid "&Hide %1"
msgstr "" msgstr ""
#: playlist/playlistheader.cpp:31 #: playlist/playlistheader.cpp:33
msgid "&Hide..." msgid "&Hide..."
msgstr "" msgstr ""
#: playlist/playlistheader.cpp:35 #: playlist/playlistheader.cpp:39
msgid "&Left" msgid "&Left"
msgstr "" msgstr ""
@ -178,7 +178,7 @@ msgstr ""
msgid "&Repeat mode" msgid "&Repeat mode"
msgstr "" msgstr ""
#: playlist/playlistheader.cpp:37 #: playlist/playlistheader.cpp:41
msgid "&Right" msgid "&Right"
msgstr "" msgstr ""
@ -186,7 +186,7 @@ msgstr ""
msgid "&Shuffle mode" msgid "&Shuffle mode"
msgstr "" msgstr ""
#: playlist/playlistheader.cpp:32 #: playlist/playlistheader.cpp:34
msgid "&Stretch columns to fit window" msgid "&Stretch columns to fit window"
msgstr "" msgstr ""