Introduce SimpleTextFloat

Introduce the new class SimpleTextFloat which simply shows a text and
that works like a pseudo tool tip with a narrow margin. It was extracted
from TextFloat to adhere to the single responsibility principle.

The new class is used by:
* Fader: display the current volume when moving the fader
* Knob: display the current value when the knob is moved
* PianoRoll: display the current value when setting the note volume and
  panning

Add stylings for the new widget in style.css.
This commit is contained in:
Michael Gregorius
2023-01-10 19:20:26 +01:00
parent 6dfdafe1f7
commit 17295a4f86
11 changed files with 143 additions and 17 deletions

View File

@@ -112,6 +112,7 @@ SET(LMMS_SRCS
gui/widgets/NStateButton.cpp
gui/widgets/Oscilloscope.cpp
gui/widgets/PixmapButton.cpp
gui/widgets/SimpleTextFloat.cpp
gui/widgets/TabBar.cpp
gui/widgets/TabWidget.cpp
gui/widgets/TempoSyncKnob.cpp

View File

@@ -66,6 +66,7 @@
#include "PatternStore.h"
#include "PianoView.h"
#include "PositionLine.h"
#include "SimpleTextFloat.h"
#include "SongEditor.h"
#include "StepRecorderWidget.h"
#include "TextFloat.h"
@@ -127,7 +128,7 @@ QPixmap * PianoRoll::s_toolMove = nullptr;
QPixmap * PianoRoll::s_toolOpen = nullptr;
QPixmap* PianoRoll::s_toolKnife = nullptr;
TextFloat * PianoRoll::s_textFloat = nullptr;
SimpleTextFloat * PianoRoll::s_textFloat = nullptr;
static std::array<QString, 12> s_noteStrings {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
@@ -290,7 +291,7 @@ PianoRoll::PianoRoll() :
// init text-float
if( s_textFloat == nullptr )
{
s_textFloat = new TextFloat;
s_textFloat = new SimpleTextFloat;
}
setAttribute( Qt::WA_OpaquePaintEvent, true );

View File

@@ -54,13 +54,13 @@
#include "embed.h"
#include "CaptionMenu.h"
#include "ConfigManager.h"
#include "TextFloat.h"
#include "SimpleTextFloat.h"
namespace lmms::gui
{
TextFloat * Fader::s_textFloat = nullptr;
SimpleTextFloat * Fader::s_textFloat = nullptr;
QPixmap * Fader::s_back = nullptr;
QPixmap * Fader::s_leds = nullptr;
QPixmap * Fader::s_knob = nullptr;
@@ -83,7 +83,7 @@ Fader::Fader( FloatModel * _model, const QString & _name, QWidget * _parent ) :
{
if( s_textFloat == nullptr )
{
s_textFloat = new TextFloat;
s_textFloat = new SimpleTextFloat;
}
if( ! s_back )
{
@@ -125,7 +125,7 @@ Fader::Fader( FloatModel * model, const QString & name, QWidget * parent, QPixma
{
if( s_textFloat == nullptr )
{
s_textFloat = new TextFloat;
s_textFloat = new SimpleTextFloat;
}
m_back = back;

View File

@@ -45,14 +45,14 @@
#include "LocaleHelper.h"
#include "MainWindow.h"
#include "ProjectJournal.h"
#include "SimpleTextFloat.h"
#include "StringPairDrag.h"
#include "TextFloat.h"
namespace lmms::gui
{
TextFloat * Knob::s_textFloat = nullptr;
SimpleTextFloat * Knob::s_textFloat = nullptr;
@@ -86,7 +86,7 @@ void Knob::initUi( const QString & _name )
{
if( s_textFloat == nullptr )
{
s_textFloat = new TextFloat;
s_textFloat = new SimpleTextFloat;
}
setWindowTitle( _name );

View File

@@ -0,0 +1,62 @@
/*
* TextFloat.cpp - class textFloat, a floating text-label
*
* Copyright (c) LMMS team
*
* This file is part of LMMS - https://lmms.io
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "SimpleTextFloat.h"
#include <QTimer>
#include <QStyleOption>
#include <QHBoxLayout>
#include <QLabel>
#include "GuiApplication.h"
#include "MainWindow.h"
namespace lmms::gui
{
SimpleTextFloat::SimpleTextFloat() :
QWidget(getGUI()->mainWindow(), Qt::ToolTip)
{
QHBoxLayout * layout = new QHBoxLayout(this);
layout->setMargin(3);
setLayout(layout);
m_textLabel = new QLabel(this);
layout->addWidget(m_textLabel);
}
void SimpleTextFloat::setText( const QString & _text )
{
m_textLabel->setText(_text);
}
void SimpleTextFloat::setVisibilityTimeOut( int _msecs )
{
QTimer::singleShot( _msecs, this, SLOT(hide()));
show();
}
} // namespace lmms::gui