2012-05-26 14:49:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MusE Score
|
|
|
|
// Linux Music Score Editor
|
|
|
|
// $Id: textpalette.cpp 3592 2010-10-18 17:24:18Z wschweer $
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002-2010 Werner Schweer and others
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2.
|
|
|
|
//
|
|
|
|
// 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; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "texttools.h"
|
|
|
|
#include "icons.h"
|
|
|
|
#include "libmscore/text.h"
|
|
|
|
#include "musescore.h"
|
|
|
|
#include "libmscore/score.h"
|
|
|
|
#include "textpalette.h"
|
|
|
|
#include "libmscore/mscore.h"
|
2013-06-18 17:02:25 +02:00
|
|
|
#include "preferences.h"
|
2017-04-11 11:34:25 +02:00
|
|
|
#include "scoreview.h"
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
TextPalette* textPalette;
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// textTools
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
TextTools* MuseScore::textTools()
|
|
|
|
{
|
|
|
|
if (!_textTools) {
|
|
|
|
_textTools = new TextTools(this);
|
2013-05-13 18:49:17 +02:00
|
|
|
addDockWidget(Qt::DockWidgetArea(Qt::BottomDockWidgetArea), _textTools);
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
return _textTools;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// TextTools
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
TextTools::TextTools(QWidget* parent)
|
|
|
|
: QDockWidget(parent)
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
_view = 0;
|
2012-05-26 14:49:10 +02:00
|
|
|
setObjectName("text-tools");
|
|
|
|
setWindowTitle(tr("Text Tools"));
|
2013-05-13 18:49:17 +02:00
|
|
|
setAllowedAreas(Qt::DockWidgetAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea));
|
2012-05-26 14:49:10 +02:00
|
|
|
|
|
|
|
QToolBar* tb = new QToolBar(tr("Text Edit"));
|
2014-11-20 09:15:17 +01:00
|
|
|
tb->setIconSize(QSize(preferences.iconWidth * guiScaling, preferences.iconHeight * guiScaling));
|
2012-05-26 14:49:10 +02:00
|
|
|
|
|
|
|
showKeyboard = getAction("show-keys");
|
|
|
|
showKeyboard->setCheckable(true);
|
2013-02-25 21:57:11 +01:00
|
|
|
tb->addAction(showKeyboard);
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2014-06-02 18:13:14 +02:00
|
|
|
typefaceBold = tb->addAction(*icons[int(Icons::textBold_ICON)], "");
|
2014-10-15 20:43:06 +02:00
|
|
|
typefaceBold->setToolTip(tr("Bold"));
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceBold->setCheckable(true);
|
|
|
|
|
2014-06-02 18:13:14 +02:00
|
|
|
typefaceItalic = tb->addAction(*icons[int(Icons::textItalic_ICON)], "");
|
2014-10-15 20:43:06 +02:00
|
|
|
typefaceItalic->setToolTip(tr("Italic"));
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceItalic->setCheckable(true);
|
|
|
|
|
2014-06-02 18:13:14 +02:00
|
|
|
typefaceUnderline = tb->addAction(*icons[int(Icons::textUnderline_ICON)], "");
|
2014-10-15 20:43:06 +02:00
|
|
|
typefaceUnderline->setToolTip(tr("Underline"));
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceUnderline->setCheckable(true);
|
|
|
|
|
|
|
|
tb->addSeparator();
|
|
|
|
|
2014-06-02 18:13:14 +02:00
|
|
|
typefaceSubscript = tb->addAction(*icons[int(Icons::textSub_ICON)], "");
|
2014-10-15 20:43:06 +02:00
|
|
|
typefaceSubscript->setToolTip(tr("Subscript"));
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceSubscript->setCheckable(true);
|
|
|
|
|
2014-06-02 18:13:14 +02:00
|
|
|
typefaceSuperscript = tb->addAction(*icons[int(Icons::textSuper_ICON)], "");
|
2014-10-15 20:43:06 +02:00
|
|
|
typefaceSuperscript->setToolTip(tr("Superscript"));
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceSuperscript->setCheckable(true);
|
|
|
|
|
|
|
|
tb->addSeparator();
|
|
|
|
|
|
|
|
typefaceFamily = new QFontComboBox(this);
|
|
|
|
tb->addWidget(typefaceFamily);
|
2014-02-11 14:27:44 +01:00
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceSize = new QDoubleSpinBox(this);
|
2014-02-21 15:02:17 +01:00
|
|
|
typefaceSize->setFocusPolicy(Qt::ClickFocus);
|
2017-03-16 06:40:22 +01:00
|
|
|
typefaceSize->setMinimum(1);
|
2012-05-26 14:49:10 +02:00
|
|
|
tb->addWidget(typefaceSize);
|
|
|
|
|
|
|
|
setWidget(tb);
|
|
|
|
QWidget* w = new QWidget(this);
|
|
|
|
setTitleBarWidget(w);
|
|
|
|
titleBarWidget()->hide();
|
|
|
|
|
|
|
|
connect(typefaceSize, SIGNAL(valueChanged(double)), SLOT(sizeChanged(double)));
|
|
|
|
connect(typefaceFamily, SIGNAL(currentFontChanged(const QFont&)), SLOT(fontChanged(const QFont&)));
|
|
|
|
connect(typefaceBold, SIGNAL(triggered(bool)), SLOT(boldClicked(bool)));
|
|
|
|
connect(typefaceItalic, SIGNAL(triggered(bool)), SLOT(italicClicked(bool)));
|
|
|
|
connect(typefaceUnderline, SIGNAL(triggered(bool)), SLOT(underlineClicked(bool)));
|
|
|
|
connect(typefaceSubscript, SIGNAL(triggered(bool)), SLOT(subscriptClicked(bool)));
|
|
|
|
connect(typefaceSuperscript, SIGNAL(triggered(bool)), SLOT(superscriptClicked(bool)));
|
2015-09-02 12:08:31 +02:00
|
|
|
connect(showKeyboard, SIGNAL(toggled(bool)), SLOT(showKeyboardClicked(bool)));
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// blockAllSignals
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::blockAllSignals(bool val)
|
|
|
|
{
|
|
|
|
typefaceSize->blockSignals(val);
|
|
|
|
typefaceFamily->blockSignals(val);
|
|
|
|
typefaceBold->blockSignals(val);
|
|
|
|
typefaceItalic->blockSignals(val);
|
|
|
|
typefaceUnderline->blockSignals(val);
|
|
|
|
typefaceSubscript->blockSignals(val);
|
|
|
|
typefaceSuperscript->blockSignals(val);
|
|
|
|
typefaceFamily->blockSignals(val);
|
|
|
|
showKeyboard->blockSignals(val);
|
|
|
|
}
|
|
|
|
|
2017-04-11 11:34:25 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// textElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Text* TextTools::textElement()
|
|
|
|
{
|
|
|
|
if (_view) {
|
|
|
|
Element* e = _view->getEditElement();
|
|
|
|
if (e && e->isText())
|
|
|
|
return toText(e);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// cursor
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
TextCursor* TextTools::cursor()
|
|
|
|
{
|
|
|
|
EditData& ed = _view->getEditData();
|
|
|
|
return textElement()->cursor(ed);
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// updateTools
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2017-04-11 11:34:25 +02:00
|
|
|
void TextTools::updateTools(EditData& ed)
|
2012-05-26 14:49:10 +02:00
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
if (!_view->getEditElement())
|
2014-03-04 13:06:23 +01:00
|
|
|
qFatal("TextTools::updateTools(): not in edit mode");
|
2017-04-11 11:34:25 +02:00
|
|
|
|
2013-02-13 19:28:53 +01:00
|
|
|
blockAllSignals(true);
|
2017-04-11 11:34:25 +02:00
|
|
|
CharFormat* format = textElement()->curFormat(ed);
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2014-02-11 14:27:44 +01:00
|
|
|
QFont f(format->fontFamily());
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceFamily->setCurrentFont(f);
|
2017-04-11 11:34:25 +02:00
|
|
|
typefaceFamily->setEnabled(format->type() == CharFormatType::TEXT);
|
2014-02-11 14:27:44 +01:00
|
|
|
typefaceSize->setValue(format->fontSize());
|
2013-02-18 12:56:09 +01:00
|
|
|
|
2014-02-11 14:27:44 +01:00
|
|
|
typefaceItalic->setChecked(format->italic());
|
|
|
|
typefaceBold->setChecked(format->bold());
|
|
|
|
typefaceUnderline->setChecked(format->underline());
|
|
|
|
typefaceSubscript->setChecked(format->valign() == VerticalAlignment::AlignSubScript);
|
|
|
|
typefaceSuperscript->setChecked(format->valign() == VerticalAlignment::AlignSuperScript);
|
2012-05-26 14:49:10 +02:00
|
|
|
|
|
|
|
blockAllSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// updateText
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::updateText()
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
if (!textElement())
|
2014-03-28 14:26:16 +01:00
|
|
|
return;
|
2017-04-11 11:34:25 +02:00
|
|
|
if (textElement()->type() == ElementType::LYRICS) {
|
|
|
|
textElement()->score()->setLayoutAll();
|
|
|
|
textElement()->score()->update();
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
layoutText();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// layoutText
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::layoutText()
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
_view->score()->setLayoutAll();
|
|
|
|
_view->score()->update();
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// sizeChanged
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::sizeChanged(double value)
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
cursor()->setFormat(FormatId::FontSize, value);
|
|
|
|
cursor()->format()->setFontSize(value);
|
2012-05-26 14:49:10 +02:00
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// fontChanged
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::fontChanged(const QFont& f)
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
if (textElement())
|
|
|
|
cursor()->setFormat(FormatId::FontFamily, f.family());
|
2014-02-13 10:43:21 +01:00
|
|
|
if (textPalette)
|
|
|
|
textPalette->setFont(f.family());
|
2012-05-26 14:49:10 +02:00
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// boldClicked
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::boldClicked(bool val)
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
cursor()->setFormat(FormatId::Bold, val);
|
2012-05-26 14:49:10 +02:00
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
2014-02-12 14:39:44 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// toggleBold
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::toggleBold()
|
|
|
|
{
|
|
|
|
typefaceBold->toggle();
|
|
|
|
boldClicked(typefaceBold->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// toggleItalic
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::toggleItalic()
|
|
|
|
{
|
|
|
|
typefaceItalic->toggle();
|
|
|
|
italicClicked(typefaceItalic->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// toggleUnderline
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::toggleUnderline()
|
|
|
|
{
|
|
|
|
typefaceUnderline->toggle();
|
|
|
|
underlineClicked(typefaceUnderline->isChecked());
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// underlineClicked
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::underlineClicked(bool val)
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
cursor()->setFormat(FormatId::Underline, val);
|
2012-05-26 14:49:10 +02:00
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// italicClicked
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::italicClicked(bool val)
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
cursor()->setFormat(FormatId::Italic, val);
|
2012-05-26 14:49:10 +02:00
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// subscriptClicked
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::subscriptClicked(bool val)
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
cursor()->setFormat(FormatId::Valign, int(val ? VerticalAlignment::AlignSubScript : VerticalAlignment::AlignNormal));
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceSuperscript->blockSignals(true);
|
|
|
|
typefaceSuperscript->setChecked(false);
|
|
|
|
typefaceSuperscript->blockSignals(false);
|
2012-10-25 13:51:57 +02:00
|
|
|
updateText();
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// superscriptClicked
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::superscriptClicked(bool val)
|
|
|
|
{
|
2017-04-11 11:34:25 +02:00
|
|
|
cursor()->setFormat(FormatId::Valign, int(val ? VerticalAlignment::AlignSuperScript : VerticalAlignment::AlignNormal));
|
2012-05-26 14:49:10 +02:00
|
|
|
typefaceSubscript->blockSignals(true);
|
|
|
|
typefaceSubscript->setChecked(false);
|
|
|
|
typefaceSubscript->blockSignals(false);
|
2012-10-25 13:51:57 +02:00
|
|
|
updateText();
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// showKeyboardClicked
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TextTools::showKeyboardClicked(bool val)
|
|
|
|
{
|
|
|
|
if (val) {
|
|
|
|
if (textPalette == 0)
|
|
|
|
textPalette = new TextPalette(mscore);
|
2017-04-11 11:34:25 +02:00
|
|
|
textPalette->setText(textElement());
|
|
|
|
textPalette->setFont(cursor()->format()->fontFamily());
|
2012-05-26 14:49:10 +02:00
|
|
|
textPalette->show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (textPalette)
|
|
|
|
textPalette->hide();
|
|
|
|
}
|
|
|
|
}
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
2012-05-26 14:49:10 +02:00
|
|
|
|