Chris@929
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@929
|
2
|
Chris@929
|
3 /*
|
Chris@929
|
4 Sonic Visualiser
|
Chris@929
|
5 An audio file viewer and annotation editor.
|
Chris@929
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@929
|
7
|
Chris@929
|
8 This program is free software; you can redistribute it and/or
|
Chris@929
|
9 modify it under the terms of the GNU General Public License as
|
Chris@929
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@929
|
11 License, or (at your option) any later version. See the file
|
Chris@929
|
12 COPYING included with this distribution for more information.
|
Chris@929
|
13 */
|
Chris@929
|
14
|
Chris@929
|
15 #include "LevelPanToolButton.h"
|
Chris@929
|
16 #include "LevelPanWidget.h"
|
Chris@929
|
17
|
Chris@929
|
18 #include <QMenu>
|
Chris@929
|
19 #include <QWidgetAction>
|
Chris@929
|
20 #include <QImage>
|
Chris@929
|
21
|
Chris@929
|
22 #include <iostream>
|
Chris@929
|
23 using std::cerr;
|
Chris@929
|
24 using std::endl;
|
Chris@929
|
25
|
Chris@929
|
26 LevelPanToolButton::LevelPanToolButton(QWidget *parent) :
|
Chris@929
|
27 QToolButton(parent),
|
Chris@929
|
28 m_pixels(32)
|
Chris@929
|
29 {
|
Chris@929
|
30 m_lpw = new LevelPanWidget();
|
Chris@929
|
31
|
Chris@929
|
32 connect(m_lpw, SIGNAL(levelChanged(float)), this, SIGNAL(levelChanged(float)));
|
Chris@929
|
33 connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(redraw()));
|
Chris@929
|
34
|
Chris@929
|
35 connect(m_lpw, SIGNAL(panChanged(float)), this, SIGNAL(panChanged(float)));
|
Chris@929
|
36 connect(m_lpw, SIGNAL(panChanged(float)), this, SLOT(redraw()));
|
Chris@929
|
37
|
Chris@929
|
38 QMenu *menu = new QMenu();
|
Chris@929
|
39 QWidgetAction *wa = new QWidgetAction(menu);
|
Chris@929
|
40 wa->setDefaultWidget(m_lpw);
|
Chris@929
|
41 menu->addAction(wa);
|
Chris@929
|
42
|
Chris@929
|
43 setPopupMode(MenuButtonPopup);
|
Chris@929
|
44 setMenu(menu);
|
Chris@929
|
45 setCheckable(true);
|
Chris@929
|
46
|
Chris@929
|
47 redraw();
|
Chris@929
|
48 }
|
Chris@929
|
49
|
Chris@929
|
50 LevelPanToolButton::~LevelPanToolButton()
|
Chris@929
|
51 {
|
Chris@929
|
52 }
|
Chris@929
|
53
|
Chris@929
|
54 float
|
Chris@929
|
55 LevelPanToolButton::getLevel() const
|
Chris@929
|
56 {
|
Chris@929
|
57 return m_lpw->getLevel();
|
Chris@929
|
58 }
|
Chris@929
|
59
|
Chris@929
|
60 float
|
Chris@929
|
61 LevelPanToolButton::getPan() const
|
Chris@929
|
62 {
|
Chris@929
|
63 return m_lpw->getPan();
|
Chris@929
|
64 }
|
Chris@929
|
65
|
Chris@929
|
66 void
|
Chris@929
|
67 LevelPanToolButton::setImageSize(int pixels)
|
Chris@929
|
68 {
|
Chris@929
|
69 m_pixels = pixels;
|
Chris@929
|
70 redraw();
|
Chris@929
|
71 }
|
Chris@929
|
72
|
Chris@929
|
73 void
|
Chris@929
|
74 LevelPanToolButton::setLevel(float level)
|
Chris@929
|
75 {
|
Chris@929
|
76 m_lpw->setLevel(level);
|
Chris@929
|
77 }
|
Chris@929
|
78
|
Chris@929
|
79 void
|
Chris@929
|
80 LevelPanToolButton::setPan(float pan)
|
Chris@929
|
81 {
|
Chris@929
|
82 m_lpw->setPan(pan);
|
Chris@929
|
83 }
|
Chris@929
|
84
|
Chris@929
|
85 void
|
Chris@929
|
86 LevelPanToolButton::redraw()
|
Chris@929
|
87 {
|
Chris@929
|
88 QSize sz(m_pixels, m_pixels);
|
Chris@929
|
89
|
Chris@929
|
90 m_lpw->setFixedWidth(m_pixels * 4);
|
Chris@929
|
91 m_lpw->setFixedHeight(m_pixels * 4);
|
Chris@929
|
92
|
Chris@929
|
93 QPixmap px(sz);
|
Chris@929
|
94 px.fill(Qt::transparent);
|
Chris@929
|
95 m_lpw->renderTo(&px, QRectF(QPointF(), sz), false);
|
Chris@929
|
96 setIcon(px);
|
Chris@929
|
97 }
|
Chris@929
|
98
|