MuseScore/mscore/texttools.cpp

311 lines
10 KiB
C++
Raw Normal View History

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"
#include "preferences.h"
#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)
{
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
2017-05-08 12:30:31 +02:00
text = nullptr;
cursor = nullptr;
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
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);
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);
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();
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);
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);
2017-07-08 11:34:58 +02:00
typefaceFamily->setEditable(false);
2012-05-26 14:49:10 +02:00
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);
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)));
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);
}
//---------------------------------------------------------
// updateTools
//---------------------------------------------------------
void TextTools::updateTools(EditData& ed)
2012-05-26 14:49:10 +02:00
{
2017-05-02 14:17:31 +02:00
text = toText(ed.element);
cursor = text->cursor(ed);
blockAllSignals(true);
2017-07-08 11:34:58 +02:00
CharFormat* format = cursor->format();
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-05-22 15:27:16 +02:00
typefaceFamily->setEnabled(true);
2014-02-11 14:27:44 +01:00
typefaceSize->setValue(format->fontSize());
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-05-02 14:17:31 +02:00
if (!text)
2014-03-28 14:26:16 +01:00
return;
2017-05-02 14:17:31 +02:00
layoutText();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// layoutText
//---------------------------------------------------------
void TextTools::layoutText()
{
2017-07-08 11:34:58 +02:00
text->triggerLayout();
2017-05-02 14:17:31 +02:00
text->score()->update();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// sizeChanged
//---------------------------------------------------------
void TextTools::sizeChanged(double value)
{
2017-05-02 14:17:31 +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-05-02 14:17:31 +02:00
if (text)
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-05-02 14:17:31 +02:00
cursor->setFormat(FormatId::Bold, val);
2012-05-26 14:49:10 +02:00
updateText();
}
//---------------------------------------------------------
// 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-05-02 14:17:31 +02:00
cursor->setFormat(FormatId::Underline, val);
2012-05-26 14:49:10 +02:00
updateText();
}
//---------------------------------------------------------
// italicClicked
//---------------------------------------------------------
void TextTools::italicClicked(bool val)
{
2017-05-02 14:17:31 +02:00
cursor->setFormat(FormatId::Italic, val);
2012-05-26 14:49:10 +02:00
updateText();
}
//---------------------------------------------------------
// subscriptClicked
//---------------------------------------------------------
void TextTools::subscriptClicked(bool val)
{
2017-05-02 14:17:31 +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);
updateText();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// superscriptClicked
//---------------------------------------------------------
void TextTools::superscriptClicked(bool val)
{
2017-05-02 14:17:31 +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);
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-05-02 14:17:31 +02:00
textPalette->setText(text);
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