Chris@929: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@929: Chris@929: /* Chris@929: Sonic Visualiser Chris@929: An audio file viewer and annotation editor. Chris@929: Centre for Digital Music, Queen Mary, University of London. Chris@929: Chris@929: This program is free software; you can redistribute it and/or Chris@929: modify it under the terms of the GNU General Public License as Chris@929: published by the Free Software Foundation; either version 2 of the Chris@929: License, or (at your option) any later version. See the file Chris@929: COPYING included with this distribution for more information. Chris@929: */ Chris@929: Chris@929: #include "LevelPanToolButton.h" Chris@929: #include "LevelPanWidget.h" Chris@929: Chris@929: #include Chris@929: #include Chris@929: #include Chris@929: Chris@929: #include Chris@929: using std::cerr; Chris@929: using std::endl; Chris@929: Chris@929: LevelPanToolButton::LevelPanToolButton(QWidget *parent) : Chris@929: QToolButton(parent), Chris@930: m_pixels(32), Chris@930: m_muted(false), Chris@930: m_savedLevel(1.f) Chris@929: { Chris@929: m_lpw = new LevelPanWidget(); Chris@929: Chris@929: connect(m_lpw, SIGNAL(levelChanged(float)), this, SIGNAL(levelChanged(float))); Chris@930: connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(selfLevelChanged(float))); Chris@929: Chris@929: connect(m_lpw, SIGNAL(panChanged(float)), this, SIGNAL(panChanged(float))); Chris@929: connect(m_lpw, SIGNAL(panChanged(float)), this, SLOT(redraw())); Chris@930: Chris@930: connect(this, SIGNAL(clicked(bool)), this, SLOT(selfClicked())); Chris@929: Chris@929: QMenu *menu = new QMenu(); Chris@929: QWidgetAction *wa = new QWidgetAction(menu); Chris@929: wa->setDefaultWidget(m_lpw); Chris@929: menu->addAction(wa); Chris@929: Chris@929: setPopupMode(MenuButtonPopup); Chris@929: setMenu(menu); Chris@929: Chris@929: redraw(); Chris@929: } Chris@929: Chris@929: LevelPanToolButton::~LevelPanToolButton() Chris@929: { Chris@929: } Chris@929: Chris@929: float Chris@929: LevelPanToolButton::getLevel() const Chris@929: { Chris@929: return m_lpw->getLevel(); Chris@929: } Chris@929: Chris@929: float Chris@929: LevelPanToolButton::getPan() const Chris@929: { Chris@929: return m_lpw->getPan(); Chris@929: } Chris@929: Chris@929: void Chris@929: LevelPanToolButton::setImageSize(int pixels) Chris@929: { Chris@929: m_pixels = pixels; Chris@929: redraw(); Chris@929: } Chris@929: Chris@929: void Chris@929: LevelPanToolButton::setLevel(float level) Chris@929: { Chris@929: m_lpw->setLevel(level); Chris@930: redraw(); Chris@929: } Chris@929: Chris@929: void Chris@929: LevelPanToolButton::setPan(float pan) Chris@929: { Chris@929: m_lpw->setPan(pan); Chris@930: redraw(); Chris@930: } Chris@930: Chris@930: void Chris@930: LevelPanToolButton::selfLevelChanged(float level) Chris@930: { Chris@930: if (level > 0.f) { Chris@930: m_muted = false; Chris@930: } else { Chris@930: m_muted = true; Chris@930: m_savedLevel = 1.f; Chris@930: } Chris@930: redraw(); Chris@930: } Chris@930: Chris@930: void Chris@930: LevelPanToolButton::selfClicked() Chris@930: { Chris@930: cerr << "selfClicked" << endl; Chris@930: Chris@930: if (m_muted) { Chris@930: m_muted = false; Chris@930: m_lpw->setLevel(m_savedLevel); Chris@930: } else { Chris@930: m_savedLevel = m_lpw->getLevel(); Chris@930: m_muted = true; Chris@930: m_lpw->setLevel(0.f); Chris@930: } Chris@930: redraw(); Chris@929: } Chris@929: Chris@929: void Chris@929: LevelPanToolButton::redraw() Chris@929: { Chris@929: QSize sz(m_pixels, m_pixels); Chris@929: Chris@929: m_lpw->setFixedWidth(m_pixels * 4); Chris@929: m_lpw->setFixedHeight(m_pixels * 4); Chris@929: Chris@929: QPixmap px(sz); Chris@929: px.fill(Qt::transparent); Chris@929: m_lpw->renderTo(&px, QRectF(QPointF(), sz), false); Chris@929: setIcon(px); Chris@929: } Chris@929: