MuseScore/mscore/paletteBoxButton.cpp

152 lines
4.9 KiB
C++
Raw Normal View History

//=============================================================================
// MuseScore
// Music Composition & Notation
//
2016-06-30 15:34:02 +02:00
// Copyright (C) 2013-2016 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "paletteBoxButton.h"
#include "palette.h"
#include "preferences.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
//---------------------------------------------------------
// PaletteBoxButton
//---------------------------------------------------------
PaletteBoxButton::PaletteBoxButton(Palette* p, QWidget* parent)
: QToolButton(parent)
{
palette = p;
editAction = 0;
setCheckable(true);
setFocusPolicy(Qt::NoFocus);
connect(this, SIGNAL(clicked(bool)), this, SLOT(showPalette(bool)));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setText(qApp->translate("Palette", palette->name().toUtf8()));
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setArrowType(Qt::RightArrow);
showPalette(false);
setObjectName("palette");
}
//---------------------------------------------------------
// contextMenuEvent
//---------------------------------------------------------
void PaletteBoxButton::contextMenuEvent(QContextMenuEvent* event)
{
QMenu menu;
QAction* actionProperties = menu.addAction(tr("Palette Properties..."));
QAction* actionInsert = menu.addAction(tr("Insert New Palette..."));
QAction* actionUp = menu.addAction(tr("Move Palette Up"));
QAction* actionDown = menu.addAction(tr("Move Palette Down"));
QAction* actionEdit = menu.addAction(tr("Enable Editing"));
actionEdit->setCheckable(true);
actionEdit->setChecked(!palette->readOnly());
bool _systemPalette = palette->systemPalette();
actionProperties->setDisabled(_systemPalette);
actionInsert->setDisabled(_systemPalette);
actionUp->setDisabled(_systemPalette);
actionDown->setDisabled(_systemPalette);
actionEdit->setDisabled(_systemPalette);
menu.addSeparator();
2016-05-19 18:06:13 +02:00
QAction* actionSave = menu.addAction(tr("Save Palette..."));
QAction* actionLoad = menu.addAction(tr("Load Palette..."));
actionLoad->setDisabled(_systemPalette);
menu.addSeparator();
QAction* actionDelete = menu.addAction(tr("Delete Palette"));
actionDelete->setDisabled(_systemPalette);
QAction* action = menu.exec(mapToGlobal(event->pos()));
if (action == actionProperties)
propertiesTriggered();
else if (action == actionInsert)
newTriggered();
else if (action == actionUp)
upTriggered();
else if (action == actionDown)
downTriggered();
else if (action == actionEdit)
enableEditing(action->isChecked());
else if (action == actionSave)
saveTriggered();
else if (action == actionLoad)
loadTriggered();
else if (action == actionDelete)
deleteTriggered();
}
//---------------------------------------------------------
// enableEditing
//---------------------------------------------------------
void PaletteBoxButton::enableEditing(bool val)
{
palette->setReadOnly(!val);
}
//---------------------------------------------------------
// changeEvent
//---------------------------------------------------------
void PaletteBoxButton::changeEvent(QEvent* ev)
{
2016-06-30 15:34:02 +02:00
QToolButton::changeEvent(ev);
if (ev->type() == QEvent::FontChange)
setFixedHeight(QFontMetrics(font()).height() + 2);
}
//---------------------------------------------------------
// showPalette
//---------------------------------------------------------
void PaletteBoxButton::showPalette(bool visible)
{
if (visible && preferences.getBool(PREF_APP_USESINGLEPALETTE)) {
// close all palettes
emit closeAll();
}
palette->setVisible(visible);
setChecked(visible);
setArrowType(visible ? Qt::DownArrow : Qt::RightArrow );
}
//---------------------------------------------------------
// sizeHint
//---------------------------------------------------------
QSize PaletteBoxButton::sizeHint() const
{
QFontMetrics fm(font());
return QSize(20, fm.lineSpacing() + 6);
}
//---------------------------------------------------------
// paintEvent
//---------------------------------------------------------
void PaletteBoxButton::paintEvent(QPaintEvent*)
{
//remove automatic menu arrow
QStylePainter p(this);
QStyleOptionToolButton opt;
initStyleOption(&opt);
opt.features &= (~QStyleOptionToolButton::HasMenu);
p.drawComplexControl(QStyle::CC_ToolButton, opt);
}
2013-05-13 18:49:17 +02:00
}