diff options
author | Florian Jung <flo@windfisch.org> | 2011-09-14 17:17:31 +0000 |
---|---|---|
committer | Florian Jung <flo@windfisch.org> | 2011-09-14 17:17:31 +0000 |
commit | 2529ef06d1227b457af051a494ddb579ef590fe3 (patch) | |
tree | e4f3d3c77d39a5395fc3fa6806af85bb3ea77392 /muse2/muse | |
parent | 187665d84e56b63f569731550c652a89cb650309 (diff) | |
parent | 42269af2e0cc7a8c7b70d89ffa270184acde3dec (diff) |
merged with trunk
tiny fix: removed bool initalizing completely
reindented cobject.cpp
Diffstat (limited to 'muse2/muse')
-rw-r--r-- | muse2/muse/cobject.cpp | 748 | ||||
-rw-r--r-- | muse2/muse/cobject.h | 2 | ||||
-rw-r--r-- | muse2/muse/midiedit/scoreedit.cpp | 2 | ||||
-rw-r--r-- | muse2/muse/mixer/rack.cpp | 7 | ||||
-rw-r--r-- | muse2/muse/mixer/rack.h | 5 | ||||
-rw-r--r-- | muse2/muse/plugin.cpp | 25 | ||||
-rw-r--r-- | muse2/muse/widgets/meter.cpp | 170 | ||||
-rw-r--r-- | muse2/muse/widgets/meter.h | 1 | ||||
-rw-r--r-- | muse2/muse/widgets/slider.cpp | 147 | ||||
-rw-r--r-- | muse2/muse/widgets/slider.h | 11 | ||||
-rw-r--r-- | muse2/muse/widgets/utils.cpp | 52 | ||||
-rw-r--r-- | muse2/muse/widgets/utils.h | 6 | ||||
-rw-r--r-- | muse2/muse/widgets/verticalmeter.cpp | 147 |
13 files changed, 737 insertions, 586 deletions
diff --git a/muse2/muse/cobject.cpp b/muse2/muse/cobject.cpp index eff6d9af..42c3cad2 100644 --- a/muse2/muse/cobject.cpp +++ b/muse2/muse/cobject.cpp @@ -1,23 +1,23 @@ //========================================================= -// MusE -// Linux Music Editor -// $Id: cobject.cpp,v 1.4 2004/02/02 12:10:09 wschweer Exp $ +// MusE +// Linux Music Editor +// $Id: cobject.cpp,v 1.4 2004/02/02 12:10:09 wschweer Exp $ // -// (C) Copyright 1999/2000 Werner Schweer (ws@seh.de) +// (C) Copyright 1999/2000 Werner Schweer (ws@seh.de) // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; version 2 of -// the License, or (at your option) any later version. +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; version 2 of +// the License, or (at your option) any later version. // -// 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. +// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // //========================================================= @@ -46,221 +46,232 @@ bool TopWin::_defaultSubwin[TOPLEVELTYPE_LAST_ENTRY]; bool TopWin::initInited=false; TopWin::TopWin(ToplevelType t, QWidget* parent, const char* name, Qt::WindowFlags f) - : QMainWindow(parent, f) - { - if (initInited==false) - initConfiguration(); - - _type=t; - - setObjectName(QString(name)); - // Allow multiple rows. Tim. - //setDockNestingEnabled(true); - setIconSize(ICON_SIZE); - - subwinAction=new QAction(tr("As subwindow"), this); - subwinAction->setCheckable(true); - connect(subwinAction, SIGNAL(toggled(bool)), SLOT(setIsMdiWin(bool))); - - shareAction=new QAction(tr("Shares tools and menu"), this); - shareAction->setCheckable(true); - connect(shareAction, SIGNAL(toggled(bool)), SLOT(shareToolsAndMenu(bool))); - - fullscreenAction=new QAction(tr("Fullscreen"), this); - fullscreenAction->setCheckable(true); - fullscreenAction->setChecked(false); - fullscreenAction->setShortcut(shortcuts[SHRT_FULLSCREEN].key); - connect(fullscreenAction, SIGNAL(toggled(bool)), SLOT(setFullscreen(bool))); - - mdisubwin=NULL; - _sharesToolsAndMenu=_defaultSubwin[_type] ? _sharesWhenSubwin[_type] : _sharesWhenFree[_type]; - if (_defaultSubwin[_type]) - setIsMdiWin(true); - - if (_sharesToolsAndMenu) - menuBar()->hide(); - - subwinAction->setChecked(isMdiWin()); - shareAction->setChecked(_sharesToolsAndMenu); - fullscreenAction->setEnabled(!isMdiWin()); - - resize(_widthInit[_type], _heightInit[_type]); - } + : QMainWindow(parent, f) +{ + if (initInited==false) + initConfiguration(); + + _type=t; + + setObjectName(QString(name)); + // Allow multiple rows. Tim. + //setDockNestingEnabled(true); + setIconSize(ICON_SIZE); + + subwinAction=new QAction(tr("As subwindow"), this); + subwinAction->setCheckable(true); + connect(subwinAction, SIGNAL(toggled(bool)), SLOT(setIsMdiWin(bool))); + + shareAction=new QAction(tr("Shares tools and menu"), this); + shareAction->setCheckable(true); + connect(shareAction, SIGNAL(toggled(bool)), SLOT(shareToolsAndMenu(bool))); + + fullscreenAction=new QAction(tr("Fullscreen"), this); + fullscreenAction->setCheckable(true); + fullscreenAction->setChecked(false); + fullscreenAction->setShortcut(shortcuts[SHRT_FULLSCREEN].key); + connect(fullscreenAction, SIGNAL(toggled(bool)), SLOT(setFullscreen(bool))); + + mdisubwin=NULL; + _sharesToolsAndMenu=_defaultSubwin[_type] ? _sharesWhenSubwin[_type] : _sharesWhenFree[_type]; + if (_defaultSubwin[_type]) + setIsMdiWin(true); + + if (_sharesToolsAndMenu) + menuBar()->hide(); + + subwinAction->setChecked(isMdiWin()); + shareAction->setChecked(_sharesToolsAndMenu); + fullscreenAction->setEnabled(!isMdiWin()); + + resize(_widthInit[_type], _heightInit[_type]); +} //--------------------------------------------------------- -// readStatus +// readStatus //--------------------------------------------------------- void TopWin::readStatus(Xml& xml) - { - for (;;) { - Xml::Token token = xml.parse(); - if (token == Xml::Error || token == Xml::End) - break; - QString tag = xml.s1(); - switch (token) { - case Xml::TagStart: - if (tag == "geometry_state") { - if (!restoreGeometry(QByteArray::fromHex(xml.parse1().toAscii()))) - fprintf(stderr,"ERROR: couldn't restore geometry. however, this is probably not really a problem.\n"); - } - else if (tag == "toolbars") { - if (!sharesToolsAndMenu()) { - if (!restoreState(QByteArray::fromHex(xml.parse1().toAscii()))) - fprintf(stderr,"ERROR: couldn't restore toolbars. however, this is not really a problem.\n"); - } - else { - _savedToolbarState=QByteArray::fromHex(xml.parse1().toAscii()); - if (_savedToolbarState.isEmpty()) - _savedToolbarState=_toolbarNonsharedInit[_type]; - } - } - else if (tag == "shares_menu") { - shareToolsAndMenu(xml.parseInt()); - } - else if (tag == "is_subwin") { - setIsMdiWin(xml.parseInt()); - } - else - xml.unknown("TopWin"); - break; - case Xml::TagEnd: - if (tag == "topwin") - return; - default: - break; - } - } - } +{ + for (;;) + { + Xml::Token token = xml.parse(); + if (token == Xml::Error || token == Xml::End) + break; + + QString tag = xml.s1(); + switch (token) + { + case Xml::TagStart: + if (tag == "geometry_state") + { + if (!restoreGeometry(QByteArray::fromHex(xml.parse1().toAscii()))) + fprintf(stderr,"ERROR: couldn't restore geometry. however, this is probably not really a problem.\n"); + } + else if (tag == "toolbars") + { + if (!sharesToolsAndMenu()) + { + if (!restoreState(QByteArray::fromHex(xml.parse1().toAscii()))) + fprintf(stderr,"ERROR: couldn't restore toolbars. however, this is not really a problem.\n"); + } + else + { + _savedToolbarState=QByteArray::fromHex(xml.parse1().toAscii()); + if (_savedToolbarState.isEmpty()) + _savedToolbarState=_toolbarNonsharedInit[_type]; + } + } + else if (tag == "shares_menu") + { + shareToolsAndMenu(xml.parseInt()); + } + else if (tag == "is_subwin") + { + setIsMdiWin(xml.parseInt()); + } + else + xml.unknown("TopWin"); + break; + + case Xml::TagEnd: + if (tag == "topwin") + return; + + default: + break; + } + } +} //--------------------------------------------------------- -// writeStatus +// writeStatus //--------------------------------------------------------- void TopWin::writeStatus(int level, Xml& xml) const - { - xml.tag(level++, "topwin"); - - // the order of these tags has a certain sense - // changing it won't break muse, but it may break proper - // restoring of the positions - xml.intTag(level, "is_subwin", isMdiWin()); - xml.strTag(level, "geometry_state", saveGeometry().toHex().data()); - xml.intTag(level, "shares_menu", sharesToolsAndMenu()); - - if (!sharesToolsAndMenu()) - xml.strTag(level, "toolbars", saveState().toHex().data()); - else - xml.strTag(level, "toolbars", _savedToolbarState.toHex().data()); - - xml.tag(level, "/topwin"); - } +{ + xml.tag(level++, "topwin"); + + // the order of these tags has a certain sense + // changing it won't break muse, but it may break proper + // restoring of the positions + xml.intTag(level, "is_subwin", isMdiWin()); + xml.strTag(level, "geometry_state", saveGeometry().toHex().data()); + xml.intTag(level, "shares_menu", sharesToolsAndMenu()); + + if (!sharesToolsAndMenu()) + xml.strTag(level, "toolbars", saveState().toHex().data()); + else + xml.strTag(level, "toolbars", _savedToolbarState.toHex().data()); + + xml.tag(level, "/topwin"); +} void TopWin::hide() { - if (mdisubwin) - mdisubwin->close(); - - QMainWindow::hide(); + if (mdisubwin) + mdisubwin->close(); + + QMainWindow::hide(); } void TopWin::show() { - if (mdisubwin) - mdisubwin->show(); - - QMainWindow::show(); + if (mdisubwin) + mdisubwin->show(); + + QMainWindow::show(); } void TopWin::setVisible(bool param) { - if (mdisubwin) - { - if (param) - mdisubwin->show(); - else - mdisubwin->close(); - } - QMainWindow::setVisible(param); + if (mdisubwin) + { + if (param) + mdisubwin->show(); + else + mdisubwin->close(); + } + QMainWindow::setVisible(param); } QMdiSubWindow* TopWin::createMdiWrapper() { - if (mdisubwin==NULL) - { - mdisubwin = new QMdiSubWindow(); - mdisubwin->setWidget(this); - } - - return mdisubwin; + if (mdisubwin==NULL) + { + mdisubwin = new QMdiSubWindow(); + mdisubwin->setWidget(this); + } + + return mdisubwin; } void TopWin::setIsMdiWin(bool val) { - if (val) - { - if (!isMdiWin()) - { - _savedToolbarState = saveState(); - int width_temp=width(); - int height_temp=height(); - bool vis=isVisible(); - - QMdiSubWindow* subwin = createMdiWrapper(); - muse->addMdiSubWindow(subwin); - subwin->resize(width_temp, height_temp); - subwin->move(0,0); - subwin->setVisible(vis); - this->QMainWindow::show(); //bypass the delegation to the subwin - - if (_sharesToolsAndMenu == _sharesWhenFree[_type]) - shareToolsAndMenu(_sharesWhenSubwin[_type]); - - fullscreenAction->setEnabled(false); - fullscreenAction->setChecked(false); - subwinAction->setChecked(true); - muse->updateWindowMenu(); - } - else - { - if (MusEGlobal::debugMsg) printf("TopWin::setIsMdiWin(true) called, but window is already a MDI win\n"); - } - } - else - { - if (isMdiWin()) - { - int width_temp=width(); - int height_temp=height(); - bool vis=isVisible(); - - QMdiSubWindow* mdisubwin_temp=mdisubwin; - mdisubwin=NULL; - setParent(NULL); - mdisubwin_temp->hide(); - delete mdisubwin_temp; - - resize(width_temp, height_temp); - setVisible(vis); - - if (_sharesToolsAndMenu == _sharesWhenSubwin[_type]) - shareToolsAndMenu(_sharesWhenFree[_type]); - - fullscreenAction->setEnabled(true); - subwinAction->setChecked(false); - muse->updateWindowMenu(); - } - else - { - if (MusEGlobal::debugMsg) printf("TopWin::setIsMdiWin(false) called, but window is not a MDI win\n"); - } - } + if (val) + { + if (!isMdiWin()) + { + _savedToolbarState = saveState(); + int width_temp=width(); + int height_temp=height(); + bool vis=isVisible(); + + QMdiSubWindow* subwin = createMdiWrapper(); + muse->addMdiSubWindow(subwin); + subwin->resize(width_temp, height_temp); + subwin->move(0,0); + subwin->setVisible(vis); + this->QMainWindow::show(); //bypass the delegation to the subwin + + if (_sharesToolsAndMenu == _sharesWhenFree[_type]) + shareToolsAndMenu(_sharesWhenSubwin[_type]); + + fullscreenAction->setEnabled(false); + fullscreenAction->setChecked(false); + subwinAction->setChecked(true); + muse->updateWindowMenu(); + } + else + { + if (MusEGlobal::debugMsg) printf("TopWin::setIsMdiWin(true) called, but window is already a MDI win\n"); + } + } + else + { + if (isMdiWin()) + { + int width_temp=width(); + int height_temp=height(); + bool vis=isVisible(); + + QMdiSubWindow* mdisubwin_temp=mdisubwin; + mdisubwin=NULL; + setParent(NULL); + mdisubwin_temp->hide(); + delete mdisubwin_temp; + + resize(width_temp, height_temp); + setVisible(vis); + + if (_sharesToolsAndMenu == _sharesWhenSubwin[_type]) + shareToolsAndMenu(_sharesWhenFree[_type]); + + fullscreenAction->setEnabled(true); + subwinAction->setChecked(false); + muse->updateWindowMenu(); + } + else + { + if (MusEGlobal::debugMsg) printf("TopWin::setIsMdiWin(false) called, but window is not a MDI win\n"); + } + } } bool TopWin::isMdiWin() const { - return (mdisubwin!=NULL); + return (mdisubwin!=NULL); } void TopWin::insertToolBar(QToolBar*, QToolBar*) { printf("ERROR: THIS SHOULD NEVER HAPPEN: TopWin::insertToolBar called, but it's not implemented! ignoring it\n"); } @@ -271,232 +282,237 @@ void TopWin::addToolBar(Qt::ToolBarArea, QToolBar* tb) { printf("ERROR: THIS SHO void TopWin::addToolBar(QToolBar* toolbar) { - _toolbars.push_back(toolbar); - - if (!_sharesToolsAndMenu) - QMainWindow::addToolBar(toolbar); - else - toolbar->hide(); - - toolbar->setIconSize(ICON_SIZE); + _toolbars.push_back(toolbar); + + if (!_sharesToolsAndMenu) + QMainWindow::addToolBar(toolbar); + else + toolbar->hide(); + + toolbar->setIconSize(ICON_SIZE); } QToolBar* TopWin::addToolBar(const QString& title) { - QToolBar* toolbar = new QToolBar(title, this); - addToolBar(toolbar); - return toolbar; + QToolBar* toolbar = new QToolBar(title, this); + addToolBar(toolbar); + return toolbar; } void TopWin::shareToolsAndMenu(bool val) { - if (_sharesToolsAndMenu == val) - { - if (MusEGlobal::debugMsg) printf("TopWin::shareToolsAndMenu() called but has no effect\n"); - return; - } - - - _sharesToolsAndMenu = val; - - if (!val) - { - muse->shareMenuAndToolbarChanged(this, false); - - for (list<QToolBar*>::iterator it=_toolbars.begin(); it!=_toolbars.end(); it++) - if (*it != NULL) - { - QMainWindow::addToolBar(*it); - (*it)->show(); - } - else - QMainWindow::addToolBarBreak(); - - restoreState(_savedToolbarState); - _savedToolbarState.clear(); - - menuBar()->show(); - } - else - { - if (_savedToolbarState.isEmpty()) // this check avoids overwriting a previously saved state - _savedToolbarState = saveState(); // (by setIsMdiWin) with a now incorrect (empty) state - - for (list<QToolBar*>::iterator it=_toolbars.begin(); it!=_toolbars.end(); it++) - if (*it != NULL) - { - QMainWindow::removeToolBar(*it); // this does NOT delete the toolbar, which is good - (*it)->setParent(NULL); - } - - menuBar()->hide(); - - muse->shareMenuAndToolbarChanged(this, true); - } - - shareAction->setChecked(val); + if (_sharesToolsAndMenu == val) + { + if (MusEGlobal::debugMsg) printf("TopWin::shareToolsAndMenu() called but has no effect\n"); + return; + } + + + _sharesToolsAndMenu = val; + + if (!val) + { + muse->shareMenuAndToolbarChanged(this, false); + + for (list<QToolBar*>::iterator it=_toolbars.begin(); it!=_toolbars.end(); it++) + if (*it != NULL) + { + QMainWindow::addToolBar(*it); + (*it)->show(); + } + else + QMainWindow::addToolBarBreak(); + + restoreState(_savedToolbarState); + _savedToolbarState.clear(); + + menuBar()->show(); + } + else + { + if (_savedToolbarState.isEmpty()) // this check avoids overwriting a previously saved state + _savedToolbarState = saveState(); // (by setIsMdiWin) with a now incorrect (empty) state + + for (list<QToolBar*>::iterator it=_toolbars.begin(); it!=_toolbars.end(); it++) + if (*it != NULL) + { + QMainWindow::removeToolBar(*it); // this does NOT delete the toolbar, which is good + (*it)->setParent(NULL); + } + + menuBar()->hide(); + + muse->shareMenuAndToolbarChanged(this, true); + } + + shareAction->setChecked(val); } //--------------------------------------------------------- -// storeInitialState +// storeInitialState //--------------------------------------------------------- void TopWin::storeInitialState() const - { - _widthInit[_type] = width(); - _heightInit[_type] = height(); - if (sharesToolsAndMenu()) - { - if (muse->getCurrentMenuSharingTopwin() == this) - _toolbarSharedInit[_type] = muse->saveState(); - } - else - _toolbarNonsharedInit[_type] = saveState(); - } +{ + _widthInit[_type] = width(); + _heightInit[_type] = height(); + if (sharesToolsAndMenu()) + { + if (muse->getCurrentMenuSharingTopwin() == this) + _toolbarSharedInit[_type] = muse->saveState(); + } + else + _toolbarNonsharedInit[_type] = saveState(); +} //initConfiguration() restores default "traditional muse" configuration void TopWin::initConfiguration() { - if (initInited==false) - { - for (int i=0;i<TOPLEVELTYPE_LAST_ENTRY;i++) - { - _widthInit[i]=800; - _heightInit[i]=600; - _sharesWhenFree[i]=false; - _sharesWhenSubwin[i]=true; - _defaultSubwin[i]=false; - } - - _defaultSubwin[ARRANGER]=true; - - initInited=true; - } + if (initInited==false) + { + for (int i=0;i<TOPLEVELTYPE_LAST_ENTRY;i++) + { + _widthInit[i]=800; + _heightInit[i]=600; + _sharesWhenFree[i]=false; + _sharesWhenSubwin[i]=true; + _defaultSubwin[i]=false; + } + + _defaultSubwin[ARRANGER]=true; + + initInited=true; + } } //--------------------------------------------------------- -// readConfiguration +// readConfiguration //--------------------------------------------------------- void TopWin::readConfiguration(ToplevelType t, Xml& xml) - { - if (initInited==false) - initConfiguration(); - - for (;;) { - Xml::Token token = xml.parse(); - if (token == Xml::Error || token == Xml::End) - break; - const QString& tag = xml.s1(); - switch (token) { - case Xml::TagStart: - if (tag == "width") - _widthInit[t] = xml.parseInt(); - else if (tag == "height") - _heightInit[t] = xml.parseInt(); - else if (tag == "nonshared_toolbars") - _toolbarNonsharedInit[t] = QByteArray::fromHex(xml.parse1().toAscii()); - else if (tag == "shared_toolbars") - _toolbarSharedInit[t] = QByteArray::fromHex(xml.parse1().toAscii()); - else if (tag == "shares_when_free") - _sharesWhenFree[t] = xml.parseInt(); - else if (tag == "shares_when_subwin") - _sharesWhenSubwin[t] = xml.parseInt(); - else if (tag == "default_subwin") - _defaultSubwin[t] = xml.parseInt(); - else - xml.unknown("TopWin"); - break; - case Xml::TagEnd: - if (tag == "topwin") - return; - default: - break; - } - } - } +{ +if (initInited==false) + initConfiguration(); + + for (;;) + { + Xml::Token token = xml.parse(); + if (token == Xml::Error || token == Xml::End) + break; + + const QString& tag = xml.s1(); + switch (token) + { + case Xml::TagStart: + if (tag == "width") + _widthInit[t] = xml.parseInt(); + else if (tag == "height") + _heightInit[t] = xml.parseInt(); + else if (tag == "nonshared_toolbars") + _toolbarNonsharedInit[t] = QByteArray::fromHex(xml.parse1().toAscii()); + else if (tag == "shared_toolbars") + _toolbarSharedInit[t] = QByteArray::fromHex(xml.parse1().toAscii()); + else if (tag == "shares_when_free") + _sharesWhenFree[t] = xml.parseInt(); + else if (tag == "shares_when_subwin") + _sharesWhenSubwin[t] = xml.parseInt(); + else if (tag == "default_subwin") + _defaultSubwin[t] = xml.parseInt(); + else + xml.unknown("TopWin"); + break; + + case Xml::TagEnd: + if (tag == "topwin") + return; + + default: + break; + } + } +} //--------------------------------------------------------- -// writeConfiguration +// writeConfiguration //--------------------------------------------------------- void TopWin::writeConfiguration(ToplevelType t, int level, Xml& xml) - { - if (!initInited) - { - printf ("WARNING: TopWin::writeConfiguration() called although the config hasn't been\n" - " initalized! writing default configuration\n"); - initConfiguration(); - } - xml.tag(level++, "topwin"); - xml.intTag(level, "width", _widthInit[t]); - xml.intTag(level, "height", _heightInit[t]); - xml.strTag(level, "nonshared_toolbars", _toolbarNonsharedInit[t].toHex().data()); - xml.strTag(level, "shared_toolbars", _toolbarSharedInit[t].toHex().data()); - xml.intTag(level, "shares_when_free", _sharesWhenFree[t]); - xml.intTag(level, "shares_when_subwin", _sharesWhenSubwin[t]); - xml.intTag(level, "default_subwin", _defaultSubwin[t]); - xml.etag(level, "topwin"); - } +{ + if (!initInited) + { + printf ("WARNING: TopWin::writeConfiguration() called although the config hasn't been\n" + " initalized! writing default configuration\n"); + initConfiguration(); + } + xml.tag(level++, "topwin"); + xml.intTag(level, "width", _widthInit[t]); + xml.intTag(level, "height", _heightInit[t]); + xml.strTag(level, "nonshared_toolbars", _toolbarNonsharedInit[t].toHex().data()); + xml.strTag(level, "shared_toolbars", _toolbarSharedInit[t].toHex().data()); + xml.intTag(level, "shares_when_free", _sharesWhenFree[t]); + xml.intTag(level, "shares_when_subwin", _sharesWhenSubwin[t]); + xml.intTag(level, "default_subwin", _defaultSubwin[t]); + xml.etag(level, "topwin"); +} void TopWin::initTopwinState() { - if (sharesToolsAndMenu()) - { - if (this == muse->getCurrentMenuSharingTopwin()) - muse->restoreState(_toolbarSharedInit[_type]); - } - else - restoreState(_toolbarNonsharedInit[_type]); + if (sharesToolsAndMenu()) + { + if (this == muse->getCurrentMenuSharingTopwin()) + muse->restoreState(_toolbarSharedInit[_type]); + } + else + restoreState(_toolbarNonsharedInit[_type]); } void TopWin::restoreMainwinState() { - if (sharesToolsAndMenu()) - initTopwinState(); + if (sharesToolsAndMenu()) + initTopwinState(); } QString TopWin::typeName(ToplevelType t) { - switch (t) - { - case PIANO_ROLL: return tr("Piano roll"); - case LISTE: return tr("List editor"); - case DRUM: return tr("Drum editor"); - case MASTER: return tr("Master track editor"); - case LMASTER: return tr("Master track list editor"); - case WAVE: return tr("Wave editor"); - case CLIPLIST: return tr("Clip list"); - case MARKER: return tr("Marker view"); - case SCORE: return tr("Score editor"); - case ARRANGER: return tr("Arranger"); - default: return tr("<unknown toplevel type>"); - } + switch (t) + { + case PIANO_ROLL: return tr("Piano roll"); + case LISTE: return tr("List editor"); + case DRUM: return tr("Drum editor"); + case MASTER: return tr("Master track editor"); + case LMASTER: return tr("Master track list editor"); + case WAVE: return tr("Wave editor"); + case CLIPLIST: return tr("Clip list"); + case MARKER: return tr("Marker view"); + case SCORE: return tr("Score editor"); + case ARRANGER: return tr("Arranger"); + default: return tr("<unknown toplevel type>"); + } } void TopWin::setFullscreen(bool val) { - if (val) - showFullScreen(); - else - showNormal(); + if (val) + showFullScreen(); + else + showNormal(); } void TopWin::resize(int w, int h) { - QMainWindow::resize(w,h); - - if (isMdiWin()) - mdisubwin->resize(w,h); + QMainWindow::resize(w,h); + + if (isMdiWin()) + mdisubwin->resize(w,h); } void TopWin::resize(const QSize& s) { - resize(s.width(), s.height()); + resize(s.width(), s.height()); } diff --git a/muse2/muse/cobject.h b/muse2/muse/cobject.h index 08fa2b47..1ee2b581 100644 --- a/muse2/muse/cobject.h +++ b/muse2/muse/cobject.h @@ -115,8 +115,6 @@ class TopWin : public QMainWindow void initTopwinState(); - bool initalizing; //if true, no state is saved - private slots: void setFullscreen(bool); diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index 8b5b52f7..ad55b33f 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4538,8 +4538,6 @@ void ScoreCanvas::add_new_parts(const std::map< Part*, std::set<Part*> >& param) * from clipboard failed. ignoring this one... ) [ not reproducible ] * * CURRENT TODO - * M o TEST pasting in editors! - * * ! o fix sigedit boxes (see also "important todo") * o ticks-to-quarter spinboxes * o newly created windows have to be focussed! diff --git a/muse2/muse/mixer/rack.cpp b/muse2/muse/mixer/rack.cpp index 9e7dc754..fdd80e60 100644 --- a/muse2/muse/mixer/rack.cpp +++ b/muse2/muse/mixer/rack.cpp @@ -84,9 +84,9 @@ void EffectRackDelegate::paint ( QPainter * painter, const QStyleOptionViewItem mask.setColorAt(1, mask_edge); mask.setStart(QPointF(0, cr.y())); mask.setFinalStop(QPointF(0, cr.y() + cr.height())); - + painter->setBrush(tr->efxPipe()->isOn(index.row()) ? - option.palette.mid() : + er->getActiveColor() : option.palette.dark()); painter->setPen(Qt::NoPen); painter->drawRoundedRect(cr, 2, 2); @@ -160,6 +160,7 @@ EffectRack::EffectRack(QWidget* parent, AudioTrack* t) track = t; itemheight = 19; setFont(MusEConfig::config.fonts[1]); + activeColor = QColor(74, 165, 49); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -186,7 +187,7 @@ void EffectRack::updateContents() for (int i = 0; i < PipelineDepth; ++i) { QString name = track->efxPipe()->name(i); item(i)->setText(name); - item(i)->setBackground(track->efxPipe()->isOn(i) ? palette().mid() : palette().dark()); + item(i)->setBackground(track->efxPipe()->isOn(i) ? activeColor : palette().dark()); item(i)->setToolTip(name == QString("empty") ? tr("effect rack") : name ); } } diff --git a/muse2/muse/mixer/rack.h b/muse2/muse/mixer/rack.h index a2f2a25a..65d112e9 100644 --- a/muse2/muse/mixer/rack.h +++ b/muse2/muse/mixer/rack.h @@ -44,7 +44,8 @@ class EffectRack : public QListWidget { AudioTrack* track; int itemheight; - + QColor activeColor; + virtual QSize minimumSizeHint() const; virtual QSize sizeHint() const; @@ -75,6 +76,8 @@ class EffectRack : public QListWidget { AudioTrack* getTrack() { return track; } QPoint getDragPos() { return dragPos; } + QColor getActiveColor() { return activeColor; } + }; #endif diff --git a/muse2/muse/plugin.cpp b/muse2/muse/plugin.cpp index 01e8243b..e2170ebb 100644 --- a/muse2/muse/plugin.cpp +++ b/muse2/muse/plugin.cpp @@ -1772,6 +1772,8 @@ void PluginI::updateControllers() //audio->msgSetPluginCtrlVal(_track, genACnum(_id, i), controls[i].val); // p4.0.21 audio->msgXXX waits. Do we really need to? _track->setPluginCtrlVal(genACnum(_id, i), controls[i].val); // TODO A faster bulk message + + song->controllerChange(_track); } //--------------------------------------------------------- @@ -3597,15 +3599,19 @@ PluginGui::PluginGui(PluginIBase* p) params[i].label->setId(i); // Let sliders all have different but unique colors - uint hast = qHash(plugin->paramName(i)); - QColor color((uint) (hast * hast) % 16777216); + // Some prime number magic + uint j = i+1; + uint c1 = j * 211 % 256; + uint c2 = j * j * 137 % 256; + uint c3 = j * j * j * 43 % 256; + QColor color(c1, c2, c3); MusEWidget::Slider* s = new MusEWidget::Slider(0, "param", Qt::Horizontal, MusEWidget::Slider::None, color); s->setCursorHoming(true); s->setId(i); - //s->setFixedHeight(h); + s->setSizeHint(200, 8); s->setRange(dlower, dupper); if(LADSPA_IS_HINT_INTEGER(range.HintDescriptor)) s->setStep(1.0); @@ -3614,7 +3620,7 @@ PluginGui::PluginGui(PluginIBase* p) params[i].label->setSlider((MusEWidget::Slider*)params[i].actuator); } //params[i].actuator->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum)); - params[i].actuator->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed)); + params[i].actuator->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); if (params[i].type == GuiParam::GUI_SLIDER) { //label->setFixedHeight(20); //label->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum)); @@ -3648,6 +3654,7 @@ PluginGui::PluginGui(PluginIBase* p) if (n2 > 0) { paramsOut = new GuiParam[n2]; + int h = fm.height() - 2; for (int i = 0; i < n2; ++i) { QLabel* label = 0; LADSPA_PortRangeHint range = plugin->rangeOut(i); @@ -3675,6 +3682,7 @@ PluginGui::PluginGui(PluginIBase* p) m->setRange(dlower, dupper); m->setVal(dval); + m->setFixedHeight(h); paramsOut[i].actuator = m; // paramsOut[i].label->setSlider((MusEWidget::Slider*)params[i].actuator); //paramsOut[i].actuator->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed)); @@ -3688,9 +3696,6 @@ PluginGui::PluginGui(PluginIBase* p) } - // p3.3.43 - resize(280, height()); - grid->setColumnStretch(2, 10); mw->setLayout(grid); view->setWidget(mw); @@ -3786,6 +3791,7 @@ void PluginGui::ctrlPressed(int param) //audio->msgSetPluginCtrlVal(track, id, val); // p4.0.21 audio->msgXXX waits. Do we really need to? track->setPluginCtrlVal(id, val); + song->controllerChange(track); track->startAutoRecord(id, val); } @@ -3805,6 +3811,7 @@ void PluginGui::ctrlPressed(int param) //audio->msgSetPluginCtrlVal(track, id, val); // p4.0.21 audio->msgXXX waits. Do we really need to? track->setPluginCtrlVal(id, val); + song->controllerChange(track); track->startAutoRecord(id, val); } @@ -3899,6 +3906,7 @@ void PluginGui::sliderChanged(double val, int param) //audio->msgSetPluginCtrlVal(track, id, val); // p4.0.21 audio->msgXXX waits. Do we really need to? track->setPluginCtrlVal(id, val); + song->controllerChange(track); track->recordAutomation(id, val); } @@ -3943,6 +3951,7 @@ void PluginGui::labelChanged(double val, int param) //audio->msgSetPluginCtrlVal(track, id, val); // p4.0.21 audio->msgXXX waits. Do we really need to? track->setPluginCtrlVal(id, val); + song->controllerChange(track); track->startAutoRecord(id, val); } @@ -4345,6 +4354,7 @@ void PluginGui::guiParamChanged(int idx) //audio->msgSetPluginCtrlVal(track, id, val); // p4.0.21 audio->msgXXX waits. Do we really need to? track->setPluginCtrlVal(id, val); + song->controllerChange(track); switch(type) { @@ -4481,6 +4491,7 @@ void PluginGui::guiSliderPressed(int idx) //audio->msgSetPluginCtrlVal(track, id, val); // p4.0.21 audio->msgXXX waits. Do we really need to? track->setPluginCtrlVal(id, val); + song->controllerChange(track); track->startAutoRecord(id, val); diff --git a/muse2/muse/widgets/meter.cpp b/muse2/muse/widgets/meter.cpp index f4d907d1..239f7655 100644 --- a/muse2/muse/widgets/meter.cpp +++ b/muse2/muse/widgets/meter.cpp @@ -30,6 +30,7 @@ #include <QResizeEvent> #include "meter.h" +#include "utils.h" #include "gconfig.h" #include "fastlog.h" @@ -47,7 +48,8 @@ Meter::Meter(QWidget* parent, MeterType type) setAttribute(Qt::WA_StaticContents); // This is absolutely required for speed! Otherwise painfully slow because we get // full rect paint events even on small scrolls! See help on QPainter::scroll(). - setAttribute(Qt::WA_OpaquePaintEvent); + // Commented out for now. Orcan 20110911 + //setAttribute(Qt::WA_OpaquePaintEvent); //setFrameStyle(QFrame::Raised | QFrame::StyledPanel); mtype = type; @@ -61,6 +63,10 @@ Meter::Meter(QWidget* parent, MeterType type) setLineWidth(0); setMidLineWidth(0); + // rounding radii + xrad = 4; + yrad = 4; + dark_red_end = QColor(0x8e0000); dark_red_begin = QColor(0x8e3800); @@ -181,19 +187,18 @@ void Meter::paintEvent(QPaintEvent* /*ev*/) // TODO: Could make better use of event rectangle, for speed. QPainter p(this); - //p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::Antialiasing); double range = maxScale - minScale; int fw = frameWidth(); int w = width() - 2*fw; int h = height() - 2*fw; - - // FIXME (Orcan): With the event rectangle we get corruption when we toggle the mono/stereo switch. Why? + /* QRect rect = ev->rect(); - int w = rect.width(); - int h = rect.height(); + int w = rect.width() - 2*fw; + int h = rect.height() - 2*fw; */ int yv; @@ -215,12 +220,15 @@ void Meter::paintEvent(QPaintEvent* /*ev*/) ymax = maxVal == 0 ? 0 : int(((maxScale - maxVal) * h)/range); p.setPen(peak_color); p.drawLine(0, ymax, w, ymax); - + // Draw the transparent layer on top of everything to give a 3d look + QPainterPath round_path = MusEUtil::roundedPath(0, 0, w, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); maskGrad.setStart(QPointF(0, 0)); maskGrad.setFinalStop(QPointF(w, 0)); - p.fillRect(0, 0, w, h, QBrush(maskGrad)); - + p.fillPath(round_path, QBrush(maskGrad)); + } @@ -250,47 +258,67 @@ void Meter::drawVU(QPainter& p, int w, int h, int yv) lightGradRed.setStart(QPointF(0, 0)); lightGradRed.setFinalStop(QPointF(0, y1)); + QPainterPath p_top = MusEUtil::roundedPath(0, 0, w, y1, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + QPainterPath p_bottom = MusEUtil::roundedPath(0, y2, w, h-y2, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + if(yv < y1) { + + QPainterPath p_dark_red = MusEUtil::roundedPath(0, 0, w, yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + p_top = p_top.subtracted(p_dark_red); + // Red section: - p.fillRect(0, 0, w, yv, QBrush(darkGradRed)); // dark red - p.fillRect(0, yv, w, y1-yv, QBrush(lightGradRed)); // light red - + p.fillPath(p_dark_red, QBrush(darkGradRed)); // dark red + p.fillPath(p_top, QBrush(lightGradRed)); // light red + // Yellow section: - p.fillRect(0, y1, w, y2-y1, QBrush(lightGradYellow)); // light yellow - + p.fillRect(0, y1, w, y2-y1, QBrush(lightGradYellow)); // light yellow + // Green section: - p.fillRect(0, y2, w, h-y2, QBrush(lightGradGreen)); // light green + p.fillPath(p_bottom, QBrush(lightGradGreen)); // light green } else if(yv < y2) { // Red section: - p.fillRect(0, 0, w, y1, QBrush(darkGradRed)); // dark red - + p.fillPath(p_top, QBrush(darkGradRed)); // dark red + // Yellow section: - p.fillRect(0, y1, w, yv-y1, QBrush(darkGradYellow)); // dark yellow - p.fillRect(0, yv, w, y2-yv, QBrush(lightGradYellow)); // light yellow - + p.fillRect(0, y1, w, yv-y1, QBrush(darkGradYellow)); // dark yellow + p.fillRect(0, yv, w, y2-yv, QBrush(lightGradYellow)); // light yellow + // Green section: - p.fillRect(0, y2, w, h-y2, QBrush(lightGradGreen)); // light green + p.fillPath(p_bottom, QBrush(lightGradGreen)); // light green } else //if(yv <= y3) { + QPainterPath p_light_green = MusEUtil::roundedPath(0, yv, w, h-yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + p_bottom = p_bottom.subtracted(p_light_green); + // Red section: - p.fillRect(0, 0, w, y1, QBrush(darkGradRed)); // dark red - + p.fillPath(p_top, QBrush(darkGradRed)); // dark red + // Yellow section: - p.fillRect(0, y1, w, y2-y1, QBrush(darkGradYellow)); // dark yellow - + p.fillRect(0, y1, w, y2-y1, QBrush(darkGradYellow)); // dark yellow + // Green section: - p.fillRect(0, y2, w, yv-y2, QBrush(darkGradGreen)); // dark green - p.fillRect(0, yv, w, h-yv, QBrush(lightGradGreen)); // light green + p.fillPath(p_bottom, QBrush(darkGradGreen)); // dark green + p.fillPath(p_light_green, QBrush(lightGradGreen)); // light green } - p.fillRect(0,y1, w, 1, separator_color); - p.fillRect(0,y2, w, 1, separator_color); + p.fillRect(0,y1, w, 1, separator_color); + p.fillRect(0,y2, w, 1, separator_color); } else @@ -301,8 +329,49 @@ void Meter::drawVU(QPainter& p, int w, int h, int yv) lightGradGreen.setStart(QPointF(0, 0)); lightGradGreen.setFinalStop(QPointF(0, h)); - p.fillRect(0, 0, w, yv, QBrush(darkGradGreen)); // dark green - p.fillRect(0, yv, w, h-yv, QBrush(lightGradGreen)); // light green + // We need to draw the meter in two parts. The cutoff for upper rectangle can be + // anywhere between yrad and h-yrad. Without loss of generality we pick the lower limit. + int cut = yrad; + + QPainterPath p_top = MusEUtil::roundedPath(0, 0, w, cut, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + QPainterPath p_bottom = MusEUtil::roundedPath(0, cut, w, h-cut, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + + if(yv < cut) + { + + QPainterPath p_dark = MusEUtil::roundedPath(0, 0, w, yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + p_top = p_top.subtracted(p_dark); + + // top section: + p.fillPath(p_dark, QBrush(darkGradGreen)); // dark green + p.fillPath(p_top, QBrush(lightGradGreen)); // light green + + // bottom section: + p.fillPath(p_bottom, QBrush(lightGradGreen)); // light green + } + else + { + QPainterPath p_light = MusEUtil::roundedPath(0, yv, w, h-yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + p_bottom = p_bottom.subtracted(p_light); + + // top section: + p.fillPath(p_top, QBrush(darkGradGreen)); // dark green + + // bottom section: + p.fillPath(p_bottom, QBrush(darkGradGreen)); // dark green + p.fillPath(p_light, QBrush(lightGradGreen)); // light green + } + } } @@ -311,43 +380,8 @@ void Meter::drawVU(QPainter& p, int w, int h, int yv) // resizeEvent //--------------------------------------------------------- -void Meter::resizeEvent(QResizeEvent* ev) - { - // Round corners of the widget. - - QSize size = ev->size(); - int w = size.width(); - int h = size.height(); - QPainterPath rounded_rect; - rounded_rect.addRoundedRect(0,0,w,h, w/2.5, w/3); - QRegion maskregion(rounded_rect.toFillPolygon().toPolygon()); - setMask(maskregion); - - /* - // Another method to do the above. I don't know yet which one is more efficient - Orcan - QRect rect(0,0,w,h); - int r = 6; - - QRegion region; - // middle and borders - region += rect.adjusted(r, 0, -r, 0); - region += rect.adjusted(0, r, 0, -r); - // top left - QRect corner(rect.topLeft(), QSize(r*2, r*2)); - region += QRegion(corner, QRegion::Ellipse); - // top right - corner.moveTopRight(rect.topRight()); - region += QRegion(corner, QRegion::Ellipse); - // bottom left - corner.moveBottomLeft(rect.bottomLeft()); - region += QRegion(corner, QRegion::Ellipse); - // bottom right - corner.moveBottomRight(rect.bottomRight()); - region += QRegion(corner, QRegion::Ellipse); - // return region; - setMask(region); - */ - + void Meter::resizeEvent(QResizeEvent* /*ev*/) + { } //--------------------------------------------------------- diff --git a/muse2/muse/widgets/meter.h b/muse2/muse/widgets/meter.h index 62ad3fe0..06f35ca2 100644 --- a/muse2/muse/widgets/meter.h +++ b/muse2/muse/widgets/meter.h @@ -72,6 +72,7 @@ class Meter : public QFrame { QColor separator_color;; QColor peak_color; + int xrad, yrad; private: MeterType mtype; diff --git a/muse2/muse/widgets/slider.cpp b/muse2/muse/widgets/slider.cpp index f50c144a..593b3df6 100644 --- a/muse2/muse/widgets/slider.cpp +++ b/muse2/muse/widgets/slider.cpp @@ -27,6 +27,7 @@ #include <QPainter> #include <QResizeEvent> +#include "utils.h" #include "slider.h" namespace MusEWidget { @@ -56,7 +57,7 @@ namespace MusEWidget { // Defaults to Horizontal. // ScalePos scalePos -- Position of the scale. Can be Slider::None, // Slider::Left, Slider::Right, Slider::Top, -// or Slider::Bottom. Defaults to Slider::None. +// or Slider::Bottom. Defaults to Slider::None. !!! CURRENTLY only Slider::None supported - oget 20110913 // QColor fillcolor -- the color used to fill in the full side // of the Slider //------------------------------------------------------------ @@ -84,6 +85,16 @@ Slider::Slider(QWidget *parent, const char *name, } //------------------------------------------------------------ +//.F Slider::setSizeHint +//------------------------------------------------------------ + +void Slider::setSizeHint(uint w, uint h) + { + horizontal_hint = w; + vertical_hint = h; + } + +//------------------------------------------------------------ //.F Slider::~Slider // Destructor //.u Syntax @@ -168,73 +179,6 @@ void Slider::fontChange(const QFont & /*oldFont*/) } //------------------------------------------------------------ -// -// roundedPath -// Returns a rectangle with rounded corners -// -// roundCorner can be an bitwise-or combination of -// UpperLeft, UpperRight, LowerRight, LowerLeft -//------------------------------------------------------------ -QPainterPath Slider::roundedPath(QRect r, int xrad, int yrad, RoundCorner roundCorner) -{ - return roundedPath(r.x(), r.y(), - r.width(), r.height(), - xrad, yrad, - roundCorner); -} - -QPainterPath Slider::roundedPath(int x, int y, int w, int h, int xrad, int yrad, RoundCorner roundCorner) -{ - QPainterPath rounded_rect; - rounded_rect.addRect(x, y + yrad, w, h - 2 * yrad); - if (roundCorner & UpperLeft) - { - rounded_rect.moveTo(x + xrad, y + yrad); - rounded_rect.arcTo(x, y, xrad*2, yrad*2, 180, -90); - } - else - { - rounded_rect.moveTo(x, y + yrad); - rounded_rect.lineTo(x,y); - rounded_rect.lineTo(x + xrad, y); - } - - rounded_rect.lineTo(x + w - xrad, y); - - if (roundCorner & UpperRight) - rounded_rect.arcTo(x + w - xrad * 2, y, xrad*2, yrad*2, 90, -90); - else - { - rounded_rect.lineTo(x + w, y); - rounded_rect.lineTo(x + w, y + yrad); - } - - if (roundCorner & LowerLeft) - { - rounded_rect.moveTo(x + xrad, y + h - yrad); - rounded_rect.arcTo(x, y + h - yrad*2, xrad*2, yrad*2, 180, 90); - } - else - { - rounded_rect.moveTo(x, y + h - yrad); - rounded_rect.lineTo(x, y + h); - rounded_rect.lineTo(x + xrad, y + h); - } - - rounded_rect.lineTo(x + w - xrad, y + h); - - if (roundCorner & LowerRight) - rounded_rect.arcTo(x + w - xrad*2, y + h - yrad*2, xrad*2, yrad*2, 270, 90); - else - { - rounded_rect.lineTo(x + w, y + h); - rounded_rect.lineTo(x + w, y + h - yrad); - } - - return rounded_rect; -} - -//------------------------------------------------------------ // drawSlider // Draw the slider into the specified rectangle. //------------------------------------------------------------ @@ -315,9 +259,9 @@ void Slider::drawSlider(QPainter *p, const QRect &r) // // Draw background // - QPainterPath bg_rect = roundedPath(cr, + QPainterPath bg_rect = MusEUtil::roundedPath(cr, xrad, yrad, - (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight) ); p->fillPath(bg_rect, d_fillColor); @@ -333,9 +277,9 @@ void Slider::drawSlider(QPainter *p, const QRect &r) e_mask.setStart(QPointF(0, cr.y())); e_mask.setFinalStop(QPointF(0, cr.y() + cr.height())); - QPainterPath e_rect = roundedPath(ipos + d_thumbLength, cr.y(), + QPainterPath e_rect = MusEUtil::roundedPath(ipos + d_thumbLength, cr.y(), cr.width() - d_thumbLength - dist1, cr.height(), - xrad, yrad, (RoundCorner) (UpperRight | LowerRight) ); + xrad, yrad, (MusEUtil::Corner) (MusEUtil::UpperRight | MusEUtil::LowerRight) ); p->fillPath(e_rect, QBrush(e_mask)); @@ -347,10 +291,10 @@ void Slider::drawSlider(QPainter *p, const QRect &r) f_mask.setStart(QPointF(0, cr.y())); f_mask.setFinalStop(QPointF(0, cr.y() + cr.height())); - QPainterPath f_rect = roundedPath(cr.x(), cr.y(), + QPainterPath f_rect = MusEUtil::roundedPath(cr.x(), cr.y(), ipos + 1, cr.height(), xrad, yrad, - (RoundCorner) (LowerLeft | UpperLeft) ); + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::UpperLeft) ); p->fillPath(f_rect, QBrush(f_mask)); @@ -359,10 +303,10 @@ void Slider::drawSlider(QPainter *p, const QRect &r) // Draw thumb // - QPainterPath thumb_rect = roundedPath(ipos, r.y(), + QPainterPath thumb_rect = MusEUtil::roundedPath(ipos, r.y(), d_thumbLength, r.height(), 2, 2, - (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight) ); thumbGrad.setStart(QPointF(0, cr.y())); thumbGrad.setFinalStop(QPointF(0, cr.y() + cr.height())); @@ -387,9 +331,9 @@ void Slider::drawSlider(QPainter *p, const QRect &r) // // Draw background // - QPainterPath bg_rect = roundedPath(cr, + QPainterPath bg_rect = MusEUtil::roundedPath(cr, xrad, yrad, - (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight) ); p->fillPath(bg_rect, d_fillColor); @@ -405,10 +349,10 @@ void Slider::drawSlider(QPainter *p, const QRect &r) e_mask.setStart(QPointF(cr.x(), 0)); e_mask.setFinalStop(QPointF(cr.x() + cr.width(), 0)); - QPainterPath e_rect = roundedPath(cr.x(), cr.y(), + QPainterPath e_rect = MusEUtil::roundedPath(cr.x(), cr.y(), cr.width(), ipos + 1, xrad, yrad, - (RoundCorner) (UpperLeft | UpperRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight) ); p->fillPath(e_rect, QBrush(e_mask)); @@ -420,9 +364,9 @@ void Slider::drawSlider(QPainter *p, const QRect &r) f_mask.setStart(QPointF(cr.x(), 0)); f_mask.setFinalStop(QPointF(cr.x() + cr.width(), 0)); - QPainterPath f_rect = roundedPath(cr.x(), ipos + d_thumbLength, + QPainterPath f_rect = MusEUtil::roundedPath(cr.x(), ipos + d_thumbLength, cr.width(), cr.height() - d_thumbLength - dist1, - xrad, yrad, (RoundCorner) (LowerLeft | LowerRight) ); + xrad, yrad, (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight) ); p->fillPath(f_rect, QBrush(f_mask)); @@ -431,10 +375,10 @@ void Slider::drawSlider(QPainter *p, const QRect &r) // Draw thumb // - QPainterPath thumb_rect = roundedPath(r.x(), ipos, + QPainterPath thumb_rect = MusEUtil::roundedPath(r.x(), ipos, r.width(), d_thumbLength, 2, 2, - (RoundCorner) (UpperLeft | UpperRight | LowerLeft | LowerRight) ); + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight) ); thumbGrad.setStart(QPointF(cr.x(), 0)); thumbGrad.setFinalStop(QPointF(cr.x() + cr.width(), 0)); @@ -606,10 +550,11 @@ void Slider::getScrollMode( QPoint &p, const Qt::MouseButton &button, int &scrol //.f void Slider::paintEvent(QPaintEvent *e) //------------------------------------------------------------ -void Slider::paintEvent(QPaintEvent* /*e*/) +void Slider::paintEvent(QPaintEvent* /*ev*/) { - QPainter p; + QPainter p(this); + /* Scale is not supported if (p.begin(this)) { if (d_scalePos != None) { p.fillRect(rect(), palette().window()); @@ -618,6 +563,8 @@ void Slider::paintEvent(QPaintEvent* /*e*/) drawSlider(&p, d_sliderRect); } p.end(); + */ + drawSlider(&p, d_sliderRect); } //------------------------------------------------------------ @@ -636,6 +583,7 @@ void Slider::resizeEvent(QResizeEvent *e) d_resized = TRUE; QSize s = e->size(); + /* Scale is not supported int sliderWidth = d_thumbWidth; // reposition slider @@ -708,8 +656,10 @@ void Slider::resizeEvent(QResizeEvent *e) s.width(), s.height()); break; } - } + */ + d_sliderRect.setRect(this->rect().x(), this->rect().y(), + s.width(), s.height()); } //------------------------------------------------------------ @@ -780,13 +730,14 @@ void Slider::setMargins(int hor, int vert) // scale. //------------------------------------------------------------ -QSize Slider::sizeHint() //const ddskrjo +QSize Slider::sizeHint() const { + /* Scale is not supported + int w = 40; + int h = 40; QPainter p; int msWidth = 0, msHeight = 0; - int w = 40; - int h = 40; if (d_scalePos != None) { if (p.begin(this)) { msWidth = d_scale.maxWidth(&p, FALSE); @@ -813,7 +764,8 @@ QSize Slider::sizeHint() //const ddskrjo break; } } - return QSize(w, h); + */ + return QSize(horizontal_hint, vertical_hint); } //--------------------------------------------------------- @@ -823,6 +775,7 @@ QSize Slider::sizeHint() //const ddskrjo void Slider::setOrientation(Qt::Orientation o) { d_orient = o; + /* Scale is not supported ScaleDraw::OrientationX so = ScaleDraw::Bottom; switch(d_orient) { case Qt::Vertical: @@ -847,6 +800,18 @@ void Slider::setOrientation(Qt::Orientation o) QRect r = geometry(); setGeometry(r.x(), r.y(), r.height(), r.width()); update(); + */ + + switch(d_orient) { + case Qt::Vertical: + horizontal_hint = 16; + vertical_hint = 64; + break; + case Qt::Horizontal: + horizontal_hint = 64; + vertical_hint = 16; + break; + } } Qt::Orientation Slider::orientation() const diff --git a/muse2/muse/widgets/slider.h b/muse2/muse/widgets/slider.h index a76c5270..5a2bff71 100644 --- a/muse2/muse/widgets/slider.h +++ b/muse2/muse/widgets/slider.h @@ -42,7 +42,6 @@ class Slider : public SliderBase, public ScaleIf public: enum ScalePos { None, Left, Right, Top, Bottom }; - enum RoundCorner { UpperLeft = 0x1, UpperRight = 0x2, LowerLeft = 0x4, LowerRight = 0x8 }; private: Q_PROPERTY( double lineStep READ lineStep WRITE setLineStep ) @@ -70,8 +69,9 @@ class Slider : public SliderBase, public ScaleIf int d_bgStyle; int markerPos; - QPainterPath roundedPath(int x, int y, int w, int h, int xrad, int yrad, RoundCorner roundCorner); - QPainterPath roundedPath(QRect r, int xrad, int yrad, RoundCorner roundCorner); + uint vertical_hint; + uint horizontal_hint; + void drawHsBgSlot(QPainter *, const QRect&, const QRect&,const QBrush&); void drawVsBgSlot(QPainter *, const QRect&, const QRect&,const QBrush&); @@ -105,8 +105,9 @@ class Slider : public SliderBase, public ScaleIf void setLineStep(double); void setPageStep(double); - void setMargins(int x, int y); - QSize sizeHint(); // const; + void setMargins(int x, int y); + virtual QSize sizeHint() const; + void setSizeHint(uint w, uint h); }; } // namespace MusEWidget diff --git a/muse2/muse/widgets/utils.cpp b/muse2/muse/widgets/utils.cpp index e46d265c..1ed9001a 100644 --- a/muse2/muse/widgets/utils.cpp +++ b/muse2/muse/widgets/utils.cpp @@ -404,4 +404,56 @@ QGradient gGradientFromQColor(const QColor& c, const QPointF& start, const QPoin return gradient; } +QPainterPath roundedPath(QRect r, int xrad, int yrad, Corner roundCorner) +{ + return roundedPath(r.x(), r.y(), + r.width(), r.height(), + xrad, yrad, + roundCorner); +} + +QPainterPath roundedPath(int x, int y, int w, int h, int xrad, int yrad, Corner roundCorner) +{ + QPainterPath rounded_rect; + rounded_rect.addRect(x, y, w, h); + + if (roundCorner & UpperLeft) + { + QPainterPath top_left_corner; + top_left_corner.addRect(x, y, xrad, yrad); + top_left_corner.moveTo(x + xrad, y + yrad); + top_left_corner.arcTo(x, y, xrad*2, yrad*2, 180, -90); + rounded_rect = rounded_rect.subtracted(top_left_corner); + } + + if (roundCorner & UpperRight) + { + QPainterPath top_right_corner; + top_right_corner.addRect(x + w - xrad, y, xrad, yrad); + top_right_corner.moveTo(x + w - xrad, y + yrad); + top_right_corner.arcTo(x + w - xrad * 2, y, xrad*2, yrad*2, 90, -90); + rounded_rect = rounded_rect.subtracted(top_right_corner); + } + + if (roundCorner & LowerLeft) + { + QPainterPath bottom_left_corner; + bottom_left_corner.addRect(x, y + h - yrad, xrad, yrad); + bottom_left_corner.moveTo(x + xrad, y + h - yrad); + bottom_left_corner.arcTo(x, y + h - yrad*2, xrad*2, yrad*2, 180, 90); + rounded_rect = rounded_rect.subtracted(bottom_left_corner); + } + + if (roundCorner & LowerRight) + { + QPainterPath bottom_right_corner; + bottom_right_corner.addRect(x + w - xrad, y + h - yrad, xrad, yrad); + bottom_right_corner.moveTo(x + w - xrad, y + h - yrad); + bottom_right_corner.arcTo(x + w - xrad*2, y + h - yrad*2, xrad*2, yrad*2, 270, 90); + rounded_rect = rounded_rect.subtracted(bottom_right_corner); + } + + return rounded_rect; +} + } // namespace MusEUtils diff --git a/muse2/muse/widgets/utils.h b/muse2/muse/widgets/utils.h index b74ba394..c6e1ad6b 100644 --- a/muse2/muse/widgets/utils.h +++ b/muse2/muse/widgets/utils.h @@ -30,9 +30,12 @@ class QGradient; class QCanvas; class QPointF; class QColor; +class QPainterPath; namespace MusEUtil { +enum Corner { UpperLeft = 0x1, UpperRight = 0x2, LowerLeft = 0x4, LowerRight = 0x8 }; + extern QString bitmap2String(int bm); extern int string2bitmap(const QString& str); extern QString u32bitmap2String(unsigned int bm); @@ -46,6 +49,9 @@ extern QFrame* vLine(QWidget* parent); extern void dump(const unsigned char* p, int n); extern double curTime(); +extern QPainterPath roundedPath(QRect r, int xrad, int yrad, Corner roundCorner); +extern QPainterPath roundedPath(int x, int y, int w, int h, int xrad, int yrad, Corner roundCorner); + } // namespace MusEUtils #endif diff --git a/muse2/muse/widgets/verticalmeter.cpp b/muse2/muse/widgets/verticalmeter.cpp index b0e0198f..74b4b695 100644 --- a/muse2/muse/widgets/verticalmeter.cpp +++ b/muse2/muse/widgets/verticalmeter.cpp @@ -31,6 +31,8 @@ #include "verticalmeter.h" #include "gconfig.h" #include "fastlog.h" +#include "mmath.h" +#include "utils.h" namespace MusEWidget { @@ -46,7 +48,8 @@ VerticalMeter::VerticalMeter(QWidget* parent, MeterType type) setAttribute(Qt::WA_StaticContents); // This is absolutely required for speed! Otherwise painfully slow because we get // full rect paint events even on small scrolls! See help on QPainter::scroll(). - setAttribute(Qt::WA_OpaquePaintEvent); + // Commented out for now. Orcan 20110911 + //setAttribute(Qt::WA_OpaquePaintEvent); mtype = type; overflow = false; @@ -56,6 +59,9 @@ VerticalMeter::VerticalMeter(QWidget* parent, MeterType type) maxScale = mtype == DBMeter ? 10.0 : 127.0; yellowScale = -10; redScale = 0; + xrad = 4; + yrad = 4; + setLineWidth(0); setMidLineWidth(0); } @@ -124,23 +130,24 @@ void VerticalMeter::setRange(double min, double max) // paintEvent //--------------------------------------------------------- -void VerticalMeter::paintEvent(QPaintEvent* ev) +void VerticalMeter::paintEvent(QPaintEvent* /*ev*/) { // TODO: Could make better use of event rectangle, for speed. QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); double range = maxScale - minScale; - /* int fw = frameWidth(); int w = width() - 2*fw; int h = height() - 2*fw; - */ + /* QRect rect = ev->rect(); - int w = rect.width(); - int h = rect.height(); + int w = rect.width() - 2*fw; + int h = rect.height() - 2*fw; + */ int xv; @@ -157,18 +164,23 @@ void VerticalMeter::paintEvent(QPaintEvent* ev) drawVU(p, w, h, xv); // Draw the peak white line. + /* int xcenter; if(mtype == DBMeter) xcenter = maxVal == 0 ? 0 : int(((maxScale - (fast_log10(0) * 20.0)) * w)/range); else - xcenter = maxVal == 0 ? 0 : int(((0) * w)/range); + xcenter = maxVal == 0 ? 0 : int(((maxVal) * w)/range); p.setPen(peak_color); p.drawLine(xcenter, 0, xcenter, h); + */ // Draw the transparent layer on top of everything to give a 3d look + QPainterPath round_path = roundedPath(0, 0, w, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight | MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); maskGrad.setStart(QPointF(0, 0)); maskGrad.setFinalStop(QPointF(0, h)); - p.fillRect(0, 0, w, h, QBrush(maskGrad)); + p.fillPath(round_path, QBrush(maskGrad)); } //--------------------------------------------------------- @@ -177,7 +189,7 @@ void VerticalMeter::paintEvent(QPaintEvent* ev) void VerticalMeter::drawVU(QPainter& p, int w, int h, int xv) { - if(mtype == DBMeter) + if(mtype == DBMeter) { double range = maxScale - minScale; int x1 = int((maxScale - redScale) * w / range); @@ -197,44 +209,65 @@ void VerticalMeter::drawVU(QPainter& p, int w, int h, int xv) lightGradRed.setStart(QPointF(0, 0)); lightGradRed.setFinalStop(QPointF(x1, 0)); + QPainterPath p_left = roundedPath(0, 0, x1, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::LowerLeft ) ); + + QPainterPath p_right = roundedPath(x2, 0, w-x2, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerRight | MusEUtil::UpperRight ) ); if(xv < x1) { - // Red section: - p.fillRect(0, 0, xv, h, QBrush(darkGradRed)); // dark red - p.fillRect(xv, 0, x1-xv, h, QBrush(lightGradRed)); // light red - + + QPainterPath p_light_green = roundedPath(0, 0, xv, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::LowerLeft ) ); + + p_left = p_left.subtracted(p_light_green); + + // Green section: + p.fillPath(p_light_green, QBrush(lightGradGreen)); // light green + p.fillPath(p_left, QBrush(darkGradGreen)); // dark green + // Yellow section: - p.fillRect(x1, 0, x2-x1, h, QBrush(lightGradYellow)); // light yellow + p.fillRect(x1, 0, x2-x1, h, QBrush(darkGradYellow)); // dark yellow - // Green section: - p.fillRect(x2, 0, w-x2, h, QBrush(lightGradGreen)); // light green + // Red section: + p.fillPath(p_right, QBrush(darkGradRed)); // dark red } else if(xv < x2) { - // Red section: - p.fillRect(0, 0, x1, h, QBrush(darkGradRed)); // dark red + // Green section: + p.fillPath(p_left, QBrush(lightGradGreen)); // light green // Yellow section: - p.fillRect(x1, 0, xv-x1, h, QBrush(darkGradYellow)); // dark yellow - p.fillRect(xv, 0, x2-xv, h, QBrush(lightGradYellow)); // light yellow + p.fillRect(x1, 0, xv-x1, h, QBrush(lightGradYellow)); // light yellow + p.fillRect(xv, 0, x2-xv, h, QBrush(darkGradYellow)); // dark yellow - // Green section: - p.fillRect(x2, 0, w-x2, h, QBrush(lightGradGreen)); // light green + // Red section: + p.fillPath(p_right, QBrush(darkGradRed)); // dark red } else - //if(yv <= y3) + //if(xv <= x3) { - // Red section: - p.fillRect(0, 0, x1, h, QBrush(darkGradRed)); // dark red + QPainterPath p_dark_red = roundedPath(xv, 0, w-xv, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerRight | MusEUtil::UpperRight ) ); + + p_right = p_right.subtracted(p_dark_red); + + // Green section: + p.fillPath(p_left, QBrush(lightGradGreen)); // light green // Yellow section: - p.fillRect(x1, 0, x2-x1, h, QBrush(darkGradYellow)); // dark yellow + p.fillRect(x1, 0, x2-x1, h, QBrush(lightGradYellow)); // light yellow - // Green section: - p.fillRect(x2, 0, xv-x2, h, QBrush(darkGradGreen)); // dark green - p.fillRect(xv, 0, w-xv, h, QBrush(lightGradGreen)); // light green + // Red section: + p.fillPath(p_right, QBrush(lightGradRed)); // light red + p.fillPath(p_dark_red, QBrush(darkGradRed)); // dark red + } p.fillRect(x1,0, 1, h, separator_color); @@ -249,8 +282,49 @@ void VerticalMeter::drawVU(QPainter& p, int w, int h, int xv) lightGradGreen.setStart(QPointF(0, 0)); lightGradGreen.setFinalStop(QPointF(w, 0)); - p.fillRect(0, 0, xv, h, QBrush(lightGradGreen)); // light green - p.fillRect(xv, 0, w-xv, h, QBrush(darkGradGreen)); // dark green + // We need to draw the meter in two parts. The cutoff for the left rectangle can be + // anywhere between xrad and w-xrad. Without loss of generality we pick the lower limit. + int cut = xrad; + + QPainterPath p_left = roundedPath(0, 0, cut, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::LowerLeft ) ); + + QPainterPath p_right = roundedPath(cut, 0, w-cut, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerRight | MusEUtil::UpperRight ) ); + + if(xv < cut) + { + + QPainterPath p_light = roundedPath(0, 0, xv, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::LowerLeft ) ); + + p_left = p_left.subtracted(p_light); + + // left section: + p.fillPath(p_left, QBrush(darkGradGreen)); // dark green + p.fillPath(p_light, QBrush(lightGradGreen)); // light green + + // bottom section: + p.fillPath(p_right, QBrush(darkGradGreen)); // dark green + } + else + { + QPainterPath p_dark = roundedPath(xv, 0, w-xv, h, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperRight | MusEUtil::LowerRight ) ); + p_right = p_right.subtracted(p_dark); + + // left section: + p.fillPath(p_left, QBrush(lightGradGreen)); // light green + + // right section: + p.fillPath(p_dark, QBrush(darkGradGreen)); // dark green + p.fillPath(p_right, QBrush(lightGradGreen)); // light green + } + } } @@ -259,17 +333,8 @@ void VerticalMeter::drawVU(QPainter& p, int w, int h, int xv) // resizeEvent //--------------------------------------------------------- -void VerticalMeter::resizeEvent(QResizeEvent* ev) +void VerticalMeter::resizeEvent(QResizeEvent* /*ev*/) { - // Round corners of the widget. - - QSize size = ev->size(); - int w = size.width(); - int h = size.height(); - QPainterPath rounded_rect; - rounded_rect.addRoundedRect(0,0,w,h, h/3, h/2.5); - QRegion maskregion(rounded_rect.toFillPolygon().toPolygon()); - setMask(maskregion); } } // namespace MusEWidget |