Mercurial > hg > svgui
comparison widgets/LevelPanToolButton.cpp @ 932:37bb4b416c52 tonioni
Render direct to widget (necessary to avoid pixel doubling on OS/X)
author | Chris Cannam |
---|---|
date | Wed, 25 Mar 2015 11:27:46 +0000 |
parents | 7cf497b72da3 |
children | 9022635c615a |
comparison
equal
deleted
inserted
replaced
931:7cf497b72da3 | 932:37bb4b416c52 |
---|---|
33 | 33 |
34 connect(m_lpw, SIGNAL(levelChanged(float)), this, SIGNAL(levelChanged(float))); | 34 connect(m_lpw, SIGNAL(levelChanged(float)), this, SIGNAL(levelChanged(float))); |
35 connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(selfLevelChanged(float))); | 35 connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(selfLevelChanged(float))); |
36 | 36 |
37 connect(m_lpw, SIGNAL(panChanged(float)), this, SIGNAL(panChanged(float))); | 37 connect(m_lpw, SIGNAL(panChanged(float)), this, SIGNAL(panChanged(float))); |
38 connect(m_lpw, SIGNAL(panChanged(float)), this, SLOT(redraw())); | 38 connect(m_lpw, SIGNAL(panChanged(float)), this, SLOT(update())); |
39 | 39 |
40 connect(this, SIGNAL(clicked(bool)), this, SLOT(selfClicked())); | 40 connect(this, SIGNAL(clicked(bool)), this, SLOT(selfClicked())); |
41 | 41 |
42 QMenu *menu = new QMenu(); | 42 QMenu *menu = new QMenu(); |
43 QWidgetAction *wa = new QWidgetAction(menu); | 43 QWidgetAction *wa = new QWidgetAction(menu); |
45 menu->addAction(wa); | 45 menu->addAction(wa); |
46 | 46 |
47 setPopupMode(MenuButtonPopup); | 47 setPopupMode(MenuButtonPopup); |
48 setMenu(menu); | 48 setMenu(menu); |
49 | 49 |
50 redraw(); | 50 setImageSize(m_pixels); |
51 } | 51 } |
52 | 52 |
53 LevelPanToolButton::~LevelPanToolButton() | 53 LevelPanToolButton::~LevelPanToolButton() |
54 { | 54 { |
55 } | 55 } |
68 | 68 |
69 void | 69 void |
70 LevelPanToolButton::setImageSize(int pixels) | 70 LevelPanToolButton::setImageSize(int pixels) |
71 { | 71 { |
72 m_pixels = pixels; | 72 m_pixels = pixels; |
73 redraw(); | 73 |
74 QPixmap px(m_pixels, m_pixels); | |
75 px.fill(Qt::transparent); | |
76 setIcon(px); | |
77 | |
78 m_lpw->setFixedWidth(m_pixels * 4); | |
79 m_lpw->setFixedHeight(m_pixels * 4); | |
74 } | 80 } |
75 | 81 |
76 void | 82 void |
77 LevelPanToolButton::setLevel(float level) | 83 LevelPanToolButton::setLevel(float level) |
78 { | 84 { |
79 m_lpw->setLevel(level); | 85 m_lpw->setLevel(level); |
80 redraw(); | 86 update(); |
81 } | 87 } |
82 | 88 |
83 void | 89 void |
84 LevelPanToolButton::setPan(float pan) | 90 LevelPanToolButton::setPan(float pan) |
85 { | 91 { |
86 m_lpw->setPan(pan); | 92 m_lpw->setPan(pan); |
87 redraw(); | 93 update(); |
88 } | 94 } |
89 | 95 |
90 void | 96 void |
91 LevelPanToolButton::selfLevelChanged(float level) | 97 LevelPanToolButton::selfLevelChanged(float level) |
92 { | 98 { |
94 m_muted = false; | 100 m_muted = false; |
95 } else { | 101 } else { |
96 m_muted = true; | 102 m_muted = true; |
97 m_savedLevel = 1.f; | 103 m_savedLevel = 1.f; |
98 } | 104 } |
99 redraw(); | 105 update(); |
100 } | 106 } |
101 | 107 |
102 void | 108 void |
103 LevelPanToolButton::selfClicked() | 109 LevelPanToolButton::selfClicked() |
104 { | 110 { |
112 m_savedLevel = m_lpw->getLevel(); | 118 m_savedLevel = m_lpw->getLevel(); |
113 m_muted = true; | 119 m_muted = true; |
114 m_lpw->setLevel(0.f); | 120 m_lpw->setLevel(0.f); |
115 emit levelChanged(0.f); | 121 emit levelChanged(0.f); |
116 } | 122 } |
117 redraw(); | 123 update(); |
118 } | 124 } |
119 | 125 |
120 void | 126 void |
121 LevelPanToolButton::redraw() | 127 LevelPanToolButton::paintEvent(QPaintEvent *e) |
122 { | 128 { |
123 QSize sz(m_pixels, m_pixels); | 129 QToolButton::paintEvent(e); |
124 | 130 double margin = (double(height()) - m_pixels) / 2.0; |
125 m_lpw->setFixedWidth(m_pixels * 4); | 131 m_lpw->renderTo(this, QRectF(margin, margin, m_pixels, m_pixels), false); |
126 m_lpw->setFixedHeight(m_pixels * 4); | |
127 | |
128 QPixmap px(sz); | |
129 px.fill(Qt::transparent); | |
130 m_lpw->renderTo(&px, QRectF(QPointF(), sz), false); | |
131 setIcon(px); | |
132 } | 132 } |
133 | 133 |
134 |