comparison widgets/LevelPanToolButton.cpp @ 929:20698aa6a517 tonioni

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