annotate widgets/LevelPanToolButton.cpp @ 935:1c529a22a6a7 tonioni

changed rectangle in Overview: colour and roundedness
author matthiasm
date Mon, 30 Mar 2015 14:14:33 +0100
parents 325a7aa69055
children a61a779d73df
rev   line source
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@930 28 m_pixels(32),
Chris@930 29 m_muted(false),
Chris@930 30 m_savedLevel(1.f)
Chris@929 31 {
Chris@929 32 m_lpw = new LevelPanWidget();
Chris@929 33
Chris@929 34 connect(m_lpw, SIGNAL(levelChanged(float)), this, SIGNAL(levelChanged(float)));
Chris@930 35 connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(selfLevelChanged(float)));
Chris@929 36
Chris@929 37 connect(m_lpw, SIGNAL(panChanged(float)), this, SIGNAL(panChanged(float)));
Chris@932 38 connect(m_lpw, SIGNAL(panChanged(float)), this, SLOT(update()));
Chris@930 39
Chris@930 40 connect(this, SIGNAL(clicked(bool)), this, SLOT(selfClicked()));
Chris@929 41
Chris@929 42 QMenu *menu = new QMenu();
Chris@929 43 QWidgetAction *wa = new QWidgetAction(menu);
Chris@929 44 wa->setDefaultWidget(m_lpw);
Chris@929 45 menu->addAction(wa);
Chris@929 46
Chris@929 47 setPopupMode(MenuButtonPopup);
Chris@929 48 setMenu(menu);
Chris@929 49
Chris@932 50 setImageSize(m_pixels);
Chris@929 51 }
Chris@929 52
Chris@929 53 LevelPanToolButton::~LevelPanToolButton()
Chris@929 54 {
Chris@929 55 }
Chris@929 56
Chris@929 57 float
Chris@929 58 LevelPanToolButton::getLevel() const
Chris@929 59 {
Chris@929 60 return m_lpw->getLevel();
Chris@929 61 }
Chris@929 62
Chris@929 63 float
Chris@929 64 LevelPanToolButton::getPan() const
Chris@929 65 {
Chris@929 66 return m_lpw->getPan();
Chris@929 67 }
Chris@929 68
Chris@929 69 void
Chris@929 70 LevelPanToolButton::setImageSize(int pixels)
Chris@929 71 {
Chris@929 72 m_pixels = pixels;
Chris@932 73
Chris@932 74 QPixmap px(m_pixels, m_pixels);
Chris@932 75 px.fill(Qt::transparent);
Chris@932 76 setIcon(px);
Chris@932 77
Chris@933 78 m_lpw->setFixedWidth(m_pixels * 3);
Chris@933 79 m_lpw->setFixedHeight(m_pixels * 3);
Chris@929 80 }
Chris@929 81
Chris@929 82 void
Chris@929 83 LevelPanToolButton::setLevel(float level)
Chris@929 84 {
Chris@929 85 m_lpw->setLevel(level);
Chris@932 86 update();
Chris@929 87 }
Chris@929 88
Chris@929 89 void
Chris@929 90 LevelPanToolButton::setPan(float pan)
Chris@929 91 {
Chris@929 92 m_lpw->setPan(pan);
Chris@932 93 update();
Chris@930 94 }
Chris@930 95
Chris@930 96 void
Chris@933 97 LevelPanToolButton::setEnabled(bool enabled)
Chris@933 98 {
Chris@933 99 m_lpw->setEnabled(enabled);
Chris@933 100 QToolButton::setEnabled(enabled);
Chris@933 101 }
Chris@933 102
Chris@933 103 void
Chris@930 104 LevelPanToolButton::selfLevelChanged(float level)
Chris@930 105 {
Chris@930 106 if (level > 0.f) {
Chris@930 107 m_muted = false;
Chris@930 108 } else {
Chris@930 109 m_muted = true;
Chris@930 110 m_savedLevel = 1.f;
Chris@930 111 }
Chris@932 112 update();
Chris@930 113 }
Chris@930 114
Chris@930 115 void
Chris@930 116 LevelPanToolButton::selfClicked()
Chris@930 117 {
Chris@930 118 cerr << "selfClicked" << endl;
Chris@930 119
Chris@930 120 if (m_muted) {
Chris@930 121 m_muted = false;
Chris@930 122 m_lpw->setLevel(m_savedLevel);
Chris@931 123 emit levelChanged(m_savedLevel);
Chris@930 124 } else {
Chris@930 125 m_savedLevel = m_lpw->getLevel();
Chris@930 126 m_muted = true;
Chris@930 127 m_lpw->setLevel(0.f);
Chris@931 128 emit levelChanged(0.f);
Chris@930 129 }
Chris@932 130 update();
Chris@929 131 }
Chris@929 132
Chris@929 133 void
Chris@932 134 LevelPanToolButton::paintEvent(QPaintEvent *e)
Chris@929 135 {
Chris@932 136 QToolButton::paintEvent(e);
Chris@934 137 if (m_pixels >= height()) {
Chris@934 138 setImageSize(height()-1);
Chris@934 139 }
Chris@932 140 double margin = (double(height()) - m_pixels) / 2.0;
Chris@932 141 m_lpw->renderTo(this, QRectF(margin, margin, m_pixels, m_pixels), false);
Chris@929 142 }
Chris@929 143
Chris@932 144