MuseScore/mscore/texttools.cpp

320 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"
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)
{
_textElement = 0;
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"));
tb->setIconSize(QSize(preferences.iconWidth, preferences.iconHeight));
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)], "");
2012-05-26 14:49:10 +02:00
typefaceBold->setToolTip(tr("bold"));
typefaceBold->setCheckable(true);
typefaceItalic = tb->addAction(*icons[int(Icons::textItalic_ICON)], "");
2012-05-26 14:49:10 +02:00
typefaceItalic->setToolTip(tr("italic"));
typefaceItalic->setCheckable(true);
typefaceUnderline = tb->addAction(*icons[int(Icons::textUnderline_ICON)], "");
2012-05-26 14:49:10 +02:00
typefaceUnderline->setToolTip(tr("underline"));
typefaceUnderline->setCheckable(true);
tb->addSeparator();
typefaceSubscript = tb->addAction(*icons[int(Icons::textSub_ICON)], "");
2012-05-26 14:49:10 +02:00
typefaceSubscript->setToolTip(tr("subscript"));
typefaceSubscript->setCheckable(true);
typefaceSuperscript = tb->addAction(*icons[int(Icons::textSuper_ICON)], "");
2012-05-26 14:49:10 +02:00
typefaceSuperscript->setToolTip(tr("superscript"));
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);
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(triggered(bool)), SLOT(showKeyboardClicked(bool)));
}
//---------------------------------------------------------
// setText
//---------------------------------------------------------
void TextTools::setText(Text* te)
{
_textElement = te;
}
//---------------------------------------------------------
// 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()
{
if (!_textElement->editMode())
qFatal("TextTools::updateTools(): not in edit mode");
blockAllSignals(true);
2014-02-11 14:27:44 +01:00
TextCursor* cursor = _textElement->cursor();
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);
2014-02-21 15:02:17 +01:00
typefaceFamily->setEnabled(cursor->format()->type() == CharFormatType::TEXT);
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()
{
2014-03-28 14:26:16 +01:00
if (!_textElement)
return;
if (_textElement->type() == Element::Type::LYRICS) {
2012-05-26 14:49:10 +02:00
_textElement->score()->setLayoutAll(true);
_textElement->score()->end();
}
else
layoutText();
}
//---------------------------------------------------------
// layoutText
//---------------------------------------------------------
void TextTools::layoutText()
{
2013-10-15 16:42:22 +02:00
_textElement->score()->setLayoutAll(true);
2012-05-26 14:49:10 +02:00
_textElement->score()->end();
}
//---------------------------------------------------------
// sizeChanged
//---------------------------------------------------------
void TextTools::sizeChanged(double value)
{
_textElement->setFormat(FormatId::FontSize, value);
2014-02-11 14:27:44 +01:00
_textElement->cursor()->format()->setFontSize(value);
2012-05-26 14:49:10 +02:00
updateText();
}
//---------------------------------------------------------
// fontChanged
//---------------------------------------------------------
void TextTools::fontChanged(const QFont& f)
{
_textElement->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)
{
_textElement->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)
{
_textElement->setFormat(FormatId::Underline, val);
2012-05-26 14:49:10 +02:00
updateText();
}
//---------------------------------------------------------
// italicClicked
//---------------------------------------------------------
void TextTools::italicClicked(bool val)
{
_textElement->setFormat(FormatId::Italic, val);
2012-05-26 14:49:10 +02:00
updateText();
}
//---------------------------------------------------------
// subscriptClicked
//---------------------------------------------------------
void TextTools::subscriptClicked(bool val)
{
_textElement->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)
{
_textElement->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);
textPalette->setText(_textElement);
2014-02-13 10:43:21 +01:00
textPalette->setFont(_textElement->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