Skip to content

Commit

Permalink
rename FxLine directly in a QLineEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
BaraMGB committed Jul 15, 2016
1 parent 81e0aaa commit 498b87f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 39 deletions.
14 changes: 13 additions & 1 deletion include/FxLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
#ifndef FX_LINE_H
#define FX_LINE_H

#include <QWidget>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsProxyWidget>
#include <QLabel>
#include <QLineEdit>
#include <QStaticText>
#include <QWidget>

#include "Knob.h"
#include "LcdWidget.h"
Expand Down Expand Up @@ -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();
Expand Down
112 changes: 74 additions & 38 deletions src/gui/widgets/FxLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
*
*/

#include "FxLine.h"

#include <QDebug>
#include <QInputDialog>
#include <QPainter>
#include <QLineEdit>
#include <QWhatsThis>

#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;
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -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 );
}


Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 498b87f

Please sign in to comment.