Mercurial > hg > easaier-soundaccess
view widgets/Slider.cpp @ 232:70b88fbbfb5c
integrate simple equalizer filter
author | lbajardsilogic |
---|---|
date | Thu, 06 Mar 2008 14:56:40 +0000 |
parents | fa034c6ae8bf |
children | 960531792d88 |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ /* Sound Access EASAIER client application. Silogic 2007. Laure Bajard. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information. */ #include <QVBoxLayout> #include "Slider.h" Slider::Slider(QWidget *parent) : QWidget(parent) , m_showTooltip(true) { QHBoxLayout *mainlayout = new QHBoxLayout(); mainlayout->setMargin(0); m_slider = new QSlider(Qt::Horizontal); m_label = new QLabel; connect(m_slider, SIGNAL(valueChanged(int)), m_label, SLOT(setNum(int))); m_label->setNum(value()); mainlayout->addWidget(m_slider); mainlayout->addWidget(m_label); setLayout(mainlayout); connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(updateToolTip())); connect(m_slider, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int))); } Slider::Slider(Qt::Orientation orientation, QWidget * parent) : QWidget(parent) , m_showTooltip(true) { QGridLayout *mainlayout = new QGridLayout(); mainlayout->setMargin(0); m_slider = new QSlider(orientation); m_label = new QLabel; connect(m_slider, SIGNAL(valueChanged(int)), m_label, SLOT(setNum(int))); m_label->setNum(value()); if (orientation == Qt::Horizontal) { mainlayout->addWidget(m_slider, 0, 0); mainlayout->addWidget(m_label, 0, 1); } else { mainlayout->addWidget(m_slider, 0, 0); mainlayout->addWidget(m_label, 1, 0); } setLayout(mainlayout); connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(updateToolTip())); connect(m_slider, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int))); } void Slider::setOrientation(Qt::Orientation or) { QLayout * cur_layout = layout(); delete cur_layout; QGridLayout *mainlayout = new QGridLayout(); mainlayout->setMargin(0); m_slider->setOrientation(or); if (or == Qt::Horizontal) { mainlayout->addWidget(m_slider, 0, 0); mainlayout->addWidget(m_label, 0, 1); } else { mainlayout->addWidget(m_slider, 0, 0); mainlayout->addWidget(m_label, 1, 0); } this->setLayout(mainlayout); } Slider::~Slider() { } void Slider::enterEvent(QEvent *e) { QWidget::enterEvent(e); QPalette palette; palette.setColor(QPalette::Button,palette.color(QPalette::Highlight)); setPalette(palette); emit mouseEntered(); } void Slider::leaveEvent(QEvent *e) { QWidget::enterEvent(e); QPalette palette; setPalette(palette); emit mouseLeft(); } void Slider::setShowToolTip(bool show) { m_showTooltip = show; /*m_noMappedUpdate = true; updateMappedValue(value()); m_noMappedUpdate = false;*/ updateToolTip(); } void Slider::updateToolTip() { if (m_showTooltip) { QString name = objectName(); QString unit = ""; QString text; //if (m_rangeMapper) unit = m_rangeMapper->getUnit(); if (name != "") { text = tr("%1: %2%3").arg(name).arg(value()).arg(unit); } else { text = tr("%2%3").arg(value()).arg(unit); } setToolTip(text); } }