From 498b87fb0ae59b765f36440b3112f5b4cca852a3 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Fri, 15 Jul 2016 12:42:44 +0200 Subject: [PATCH] rename FxLine directly in a QLineEdit --- include/FxLine.h | 14 ++++- src/gui/widgets/FxLine.cpp | 112 ++++++++++++++++++++++++------------- 2 files changed, 87 insertions(+), 39 deletions(-) diff --git a/include/FxLine.h b/include/FxLine.h index c485eceb709..ca5ca5e8c3a 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -26,9 +26,14 @@ #ifndef FX_LINE_H #define FX_LINE_H -#include +#include +#include +#include +#include #include +#include #include +#include #include "Knob.h" #include "LcdWidget.h" @@ -91,11 +96,18 @@ class FxLine : public QWidget QColor m_strokeInnerInactive; static QPixmap * s_sendBgArrow; static QPixmap * s_receiveBgArrow; + bool m_inRename; + QString m_newName; + QLineEdit * m_renameLineEdit; + QGraphicsProxyWidget * m_proxyWidget; + QGraphicsView * m_view; + QGraphicsScene * m_scene; QStaticText m_staticTextName; private slots: void renameChannel(); + void renameFinished(); void removeChannel(); void removeUnusedChannels(); void moveChannelLeft(); diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 249afdf0a91..fef903bd03c 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -23,22 +23,22 @@ * */ -#include "FxLine.h" -#include #include #include #include #include -#include "FxMixer.h" -#include "FxMixerView.h" +#include "CaptionMenu.h" #include "embed.h" #include "Engine.h" +#include "FxLine.h" +#include "FxMixer.h" +#include "FxMixerView.h" +#include "gui_templates.h" #include "GuiApplication.h" #include "SendButtonIndicator.h" -#include "gui_templates.h" -#include "CaptionMenu.h" + const int FxLine::FxLineHeight = 287; QPixmap * FxLine::s_sendBgArrow = NULL; @@ -52,7 +52,8 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex) : m_strokeOuterActive( 0, 0, 0 ), m_strokeOuterInactive( 0, 0, 0 ), m_strokeInnerActive( 0, 0, 0 ), - m_strokeInnerInactive( 0, 0, 0 ) + m_strokeInnerInactive( 0, 0, 0 ), + m_inRename( false ) { if( ! s_sendBgArrow ) { @@ -98,6 +99,16 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex) : FxMixer * mix = Engine::fxMixer(); setToolTip( mix->effectChannel( m_channelIndex )->m_name ); + + m_renameLineEdit = new QLineEdit(); + m_scene = new QGraphicsScene(); + m_scene->setSceneRect( 0, 0, 33, FxLineHeight ); + m_view = new QGraphicsView( this ); + m_view->setStyleSheet( "border-style: none; background: transparent;"); + m_view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + m_view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + m_view->setScene( m_scene ); + m_view->hide(); } @@ -149,30 +160,33 @@ void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, const QString& name, p->drawPixmap( 2, 0, 29, 56, *s_receiveBgArrow ); } - // draw the channel name - if( m_staticTextName.text() != name ) + // draw the channel name. In rename mode don't draw the name + if( !m_inRename ) { - // elide the name of the fxLine when its too long - const int maxTextHeight = 78; - QFontMetrics metrics( fxLine->font() ); - QString elidedName = metrics.elidedText( name, Qt::ElideRight, maxTextHeight ); - m_staticTextName.setText( elidedName ); + if( m_staticTextName.text() != name ) + { + // elide the name of the fxLine when its too long + const int maxTextHeight = 78; + QFontMetrics metrics( fxLine->font() ); + QString elidedName = metrics.elidedText( name, Qt::ElideRight, maxTextHeight ); + m_staticTextName.setText( elidedName ); + } + p->rotate( -90 ); + + p->setFont( pointSizeF( fxLine->font(), 7.5f ) ); + + // Coordinates of the foreground text + int const textLeft = -145; + int const textTop = 9; + + // Draw text shadow + p->setPen( sh_color ); + p->drawStaticText( textLeft - 1, textTop + 1, m_staticTextName ); + + // Draw foreground text + p->setPen( isActive ? bt_color : te_color ); + p->drawStaticText( textLeft, textTop, m_staticTextName ); } - p->rotate( -90 ); - - p->setFont( pointSizeF( fxLine->font(), 7.5f ) ); - - // Coordinates of the foreground text - int const textLeft = -145; - int const textTop = 9; - - // Draw text shadow - p->setPen( sh_color ); - p->drawStaticText( textLeft - 1, textTop + 1, m_staticTextName ); - - // Draw foreground text - p->setPen( isActive ? bt_color : te_color ); - p->drawStaticText( textLeft, textTop, m_staticTextName ); } @@ -235,17 +249,39 @@ void FxLine::contextMenuEvent( QContextMenuEvent * ) void FxLine::renameChannel() { - bool ok; + // don't draw the name + m_inRename = true; + update(); + + FxMixer * mix = Engine::fxMixer(); + m_proxyWidget = m_scene->addWidget( m_renameLineEdit ); + m_view->show(); + m_lcd->hide(); + + m_proxyWidget->setFlag( QGraphicsItem::ItemIsFocusable); + m_view->setFocus(); + m_renameLineEdit->setText( mix->effectChannel( m_channelIndex )->m_name ); + m_renameLineEdit->selectAll(); + m_renameLineEdit->setFocus(); + + m_proxyWidget->setRotation( -90 ); + m_proxyWidget->setPos( 8, 140 ); + m_renameLineEdit->setFixedWidth( 120 ); + + connect( m_renameLineEdit, SIGNAL( editingFinished() ), this, SLOT( renameFinished() ) ); +} + +void FxLine::renameFinished() +{ + m_lcd->show(); + m_view->hide(); + m_inRename = false; + m_newName = m_renameLineEdit->text(); FxMixer * mix = Engine::fxMixer(); - QString new_name = QInputDialog::getText( this, - FxMixerView::tr( "Rename FX channel" ), - FxMixerView::tr( "Enter the new name for this " - "FX channel" ), - QLineEdit::Normal, mix->effectChannel(m_channelIndex)->m_name, &ok ); - if( ok && !new_name.isEmpty() ) + if( !m_newName.isEmpty() ) { - mix->effectChannel( m_channelIndex )->m_name = new_name; - setToolTip( new_name ); + mix->effectChannel( m_channelIndex )->m_name = m_newName; + setToolTip( m_newName ); update(); } }