~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/playlist/playlistheader.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <QMenu>
24
24
#include <QSignalMapper>
25
25
 
26
 
PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, QWidget* parent)
 
26
PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, PlaylistView* view,
 
27
                               QWidget* parent)
27
28
    : StretchHeaderView(orientation, parent),
 
29
      view_(view),
28
30
      menu_(new QMenu(this)),
29
31
      show_mapper_(new QSignalMapper(this))
30
32
{
32
34
  stretch_action_ = menu_->addAction(tr("&Stretch columns to fit window"), this, SLOT(ToggleStretchEnabled()));
33
35
  menu_->addSeparator();
34
36
 
35
 
  QMenu* align_menu = new QMenu(tr("&Align text"), this);
36
 
  align_left_action_ = align_menu->addAction(tr("&Left"), this, SLOT(AlignCurrentLeft()));
37
 
  align_center_action_ = align_menu->addAction(tr("&Center"), this, SLOT(AlignCurrentCenter()));
38
 
  align_right_action_ = align_menu->addAction(tr("&Right"), this, SLOT(AlignCurrentRight()));
 
37
  QMenu* align_menu         = new QMenu(tr("&Align text"), this);
 
38
  QActionGroup* align_group = new QActionGroup(this);
 
39
  align_left_action_        = new QAction(tr("&Left"), align_group);
 
40
  align_center_action_      = new QAction(tr("&Center"), align_group);
 
41
  align_right_action_       = new QAction(tr("&Right"), align_group);
 
42
 
 
43
  align_left_action_->setCheckable(true);
 
44
  align_center_action_->setCheckable(true);
 
45
  align_right_action_->setCheckable(true);
 
46
  align_menu->addActions(align_group->actions());
 
47
 
 
48
  connect(align_group, SIGNAL(triggered(QAction*)), SLOT(SetColumnAlignment(QAction*)));
39
49
 
40
50
  menu_->addMenu(align_menu);
41
51
  menu_->addSeparator();
50
60
void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) {
51
61
  menu_section_ = logicalIndexAt(e->pos());
52
62
 
53
 
  if (menu_section_ == -1 || (
54
 
        menu_section_ == logicalIndex(0) && logicalIndex(1) == -1))
 
63
  if (menu_section_ == -1 ||
 
64
      (menu_section_ == logicalIndex(0) && logicalIndex(1) == -1))
55
65
    hide_action_->setVisible(false);
56
66
  else {
57
67
    hide_action_->setVisible(true);
58
68
 
59
69
    QString title(model()->headerData(menu_section_, Qt::Horizontal).toString());
60
70
    hide_action_->setText(tr("&Hide %1").arg(title));
 
71
 
 
72
    Qt::Alignment alignment = view_->column_alignment(menu_section_);
 
73
    if      (alignment & Qt::AlignLeft)    align_left_action_->setChecked(true);
 
74
    else if (alignment & Qt::AlignHCenter) align_center_action_->setChecked(true);
 
75
    else if (alignment & Qt::AlignRight)   align_right_action_->setChecked(true);
61
76
  }
62
77
 
63
78
  qDeleteAll(show_actions_);
87
102
  SetSectionHidden(menu_section_, true);
88
103
}
89
104
 
90
 
void PlaylistHeader::AlignCurrentLeft() {
91
 
  if (menu_section_ == -1)
92
 
    return;
93
 
  PlaylistView* view = static_cast<PlaylistView*>(parent());
94
 
  view->playlist()->set_column_align_left(menu_section_);
95
 
  emit ColumnAlignmentChanged();
96
 
}
97
 
 
98
 
void PlaylistHeader::AlignCurrentCenter() {
99
 
  if (menu_section_ == -1)
100
 
    return;
101
 
  PlaylistView* view = static_cast<PlaylistView*>(parent());
102
 
  view->playlist()->set_column_align_center(menu_section_);
103
 
  emit ColumnAlignmentChanged();
104
 
}
105
 
 
106
 
void PlaylistHeader::AlignCurrentRight() {
107
 
  if (menu_section_ == -1)
108
 
    return;
109
 
  PlaylistView* view = static_cast<PlaylistView*>(parent());
110
 
  view->playlist()->set_column_align_right(menu_section_);
111
 
  emit ColumnAlignmentChanged();
 
105
void PlaylistHeader::SetColumnAlignment(QAction* action) {
 
106
  Qt::Alignment alignment = Qt::AlignVCenter;
 
107
 
 
108
  if (action == align_left_action_)   alignment |= Qt::AlignLeft;
 
109
  if (action == align_center_action_) alignment |= Qt::AlignHCenter;
 
110
  if (action == align_right_action_)  alignment |= Qt::AlignRight;
 
111
 
 
112
  view_->SetColumnAlignment(menu_section_, alignment);
112
113
}
113
114
 
114
115
void PlaylistHeader::ToggleVisible(int section) {