diff --git a/resources/images/cache_circle.png b/resources/images/cache_circle.png new file mode 100644 index 00000000..58342c56 Binary files /dev/null and b/resources/images/cache_circle.png differ diff --git a/resources/images/cache_close.png b/resources/images/cache_close.png new file mode 100644 index 00000000..b5341287 Binary files /dev/null and b/resources/images/cache_close.png differ diff --git a/resources/images/cache_open.png b/resources/images/cache_open.png new file mode 100644 index 00000000..ceef7ed2 Binary files /dev/null and b/resources/images/cache_open.png differ diff --git a/resources/images/cache_square.png b/resources/images/cache_square.png new file mode 100644 index 00000000..78306b40 Binary files /dev/null and b/resources/images/cache_square.png differ diff --git a/resources/sankore.qrc b/resources/sankore.qrc index ebd0fc91..5b7fa1aa 100644 --- a/resources/sankore.qrc +++ b/resources/sankore.qrc @@ -317,5 +317,10 @@ images/library_open.png images/pages_close.png images/pages_open.png + images/cache_close.png + images/cache_open.png + style.qss + images/cache_circle.png + images/cache_square.png diff --git a/resources/style.qss b/resources/style.qss new file mode 100644 index 00000000..57e2b47d --- /dev/null +++ b/resources/style.qss @@ -0,0 +1,52 @@ +QWidget#DockPaletteWidgetBox +{ + background: #EEEEEE; + border-radius: 10px; + border: 2px solid #999999; +} + +QColorDialog +{ + background: #EEEEEE; +} + +QLabel#DockPaletteWidgetTitle +{ + color: #FFFFFF; + font-size : 18px; + font-weight:bold; +} + +QPushButton#DockPaletteWidgetButton +{ + background-color : #DDDDDD; + color : #555555; + border-radius : 6px; + padding : 5px; + font-weight : bold; + font-size : 12px; +} + +QPushButton#DockPaletteWidgetButton::checked +{ + background-color: #BBBBBB; +} + +QSlider::handle::horizontal +{ + background-color:#EEEEEE; + margin-top:-5px; + margin-bottom:-5px; + height:20px; + width:18px; + border-radius:10px; + border:1px solid #555555; +} + +QSlider::groove::horizontal +{ + background-color:#999999; + height:10px; + border-radius:5px; + border:1px solid #555555; +} \ No newline at end of file diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index acfdce99..ee5c1aae 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -48,6 +48,7 @@ #include "core/UBSettings.h" #include "core/UBSetting.h" #include "core/UBPersistenceManager.h" +#include "core/UBApplication.h" #include "pdf/PDFRenderer.h" @@ -672,6 +673,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(cache); scene->registerTool(cache); + UBApplication::boardController->notifyCache(true); } } else if (mXmlReader.name() == "foreignObject") @@ -2680,7 +2682,24 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() UBGraphicsCache* UBSvgSubsetAdaptor::UBSvgSubsetReader::cacheFromSvg() { UBGraphicsCache* pCache = new UBGraphicsCache(); + //pCache->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCache); pCache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); + + graphicsItemFromSvg(pCache); + + QStringRef colorR = mXmlReader.attributes().value("colorR"); + QStringRef colorG = mXmlReader.attributes().value("colorG"); + QStringRef colorB = mXmlReader.attributes().value("colorB"); + QStringRef colorA = mXmlReader.attributes().value("colorA"); + QStringRef shape = mXmlReader.attributes().value("shape"); + QStringRef shapeSize = mXmlReader.attributes().value("shapeSize"); + + QColor color(colorR.toString().toInt(), colorG.toString().toInt(), colorB.toString().toInt(), colorA.toString().toInt()); + + pCache->setMaskColor(color); + pCache->setShapeWidth(shapeSize.toString().toInt()); + pCache->setMaskShape(static_cast(shape.toString().toInt())); + pCache->setVisible(true); return pCache; @@ -2694,6 +2713,12 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::cacheToSvg(UBGraphicsCache* item) mXmlWriter.writeAttribute("y", QString("%1").arg(item->rect().y())); mXmlWriter.writeAttribute("width", QString("%1").arg(item->rect().width())); mXmlWriter.writeAttribute("height", QString("%1").arg(item->rect().height())); + mXmlWriter.writeAttribute("colorR", QString("%1").arg(item->maskColor().red())); + mXmlWriter.writeAttribute("colorG", QString("%1").arg(item->maskColor().green())); + mXmlWriter.writeAttribute("colorB", QString("%1").arg(item->maskColor().blue())); + mXmlWriter.writeAttribute("colorA", QString("%1").arg(item->maskColor().alpha())); + mXmlWriter.writeAttribute("shape", QString("%1").arg(item->maskshape())); + mXmlWriter.writeAttribute("shapeSize", QString("%1").arg(item->shapeWidth())); QString zs; zs.setNum(item->zValue(), 'f'); // 'f' keeps precision diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 867ddac4..cd1a4fed 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -484,6 +484,7 @@ void UBBoardController::addScene(UBDocumentProxy* proxy, int sceneIndex, bool re if (scene) { addScene(scene, replaceActiveIfEmpty); + emit pageChanged(); } } @@ -501,6 +502,8 @@ void UBBoardController::duplicateScene() setActiveDocumentScene(mActiveDocument, mActiveSceneIndex + 1); QApplication::restoreOverrideCursor(); + + emit pageChanged(); } @@ -669,6 +672,7 @@ void UBBoardController::previousScene() } updateActionStates(); + emit pageChanged(); } @@ -683,7 +687,7 @@ void UBBoardController::nextScene() } updateActionStates(); - + emit pageChanged(); } @@ -698,6 +702,7 @@ void UBBoardController::firstScene() } updateActionStates(); + emit pageChanged(); } @@ -712,6 +717,7 @@ void UBBoardController::lastScene() } updateActionStates(); + emit pageChanged(); } @@ -1017,6 +1023,11 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString mActiveScene->addTriangle(pPos); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + else if (sourceUrl.toString() == UBToolsManager::manager()->cache.id) + { + mActiveScene->addCache(); + UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + } else if (sourceUrl.toString() == UBToolsManager::manager()->magnifier.id) { UBMagnifierParams params; @@ -1145,7 +1156,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, } // Notify the navigator palette that the document has changed - mPaletteManager->leftPalette()->pageNavigator()->setDocument(pDocumentProxy); + mPaletteManager->leftPalette()->pageNavigator()->setDocument(pDocumentProxy); if (sceneChange) emit activeSceneChanged(); @@ -1516,6 +1527,17 @@ void UBBoardController::setPageSize(QSize newSize) } } +void UBBoardController::notifyCache(bool visible) +{ + if(visible) + { + emit cacheEnabled(); + } + else + { + emit cacheDisabled(); + } +} void UBBoardController::updatePageSizeState() { @@ -1928,7 +1950,6 @@ void UBBoardController::addItem() } } - void UBBoardController::importPage() { int pageCount = mActiveDocument->pageCount(); @@ -1939,7 +1960,10 @@ void UBBoardController::importPage() } } - +void UBBoardController::notifyPageChanged() +{ + emit pageChanged(); +} diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index f8889fce..f53dcbd7 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -157,6 +157,9 @@ class UBBoardController : public QObject return mPaletteManager; } + void notifyCache(bool visible); + void notifyPageChanged(); + public slots: void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0); @@ -255,6 +258,9 @@ class UBBoardController : public QObject void controlViewportChanged(); void backgroundChanged(); + void cacheEnabled(); + void cacheDisabled(); + void pageChanged(); protected: diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 90e2dfd3..c72ccfdd 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -600,3 +600,19 @@ void UBStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, if (textRole != QPalette::NoRole) painter->setPen(savedPen); } + +QString UBApplication::globalStyleSheet() +{ + QString style; + + QFile f(":style.qss"); + if(f.exists()) + { + if(f.open(QIODevice::ReadOnly)) + { + style = QString(f.readAll()); + } + } + + return style; +} diff --git a/src/core/UBApplication.h b/src/core/UBApplication.h index 88fe7969..a68d928a 100644 --- a/src/core/UBApplication.h +++ b/src/core/UBApplication.h @@ -78,6 +78,7 @@ class UBApplication : public QtSingleApplication static void setDisabled(bool disable); static QObject* staticMemoryCleaner; + static QString globalStyleSheet(); void decorateActionMenu(QAction* action); void insertSpaceToToolbarBeforeAction(QToolBar* toolbar, QAction* action, int width = -1); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index f908c9e6..78d33d8e 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -36,6 +36,7 @@ #include "tools/UBGraphicsCompass.h" #include "tools/UBGraphicsTriangle.h" #include "tools/UBGraphicsCurtainItem.h" +#include "tools/UBGraphicsCache.h" #include "document/UBDocumentProxy.h" @@ -1626,6 +1627,25 @@ void UBGraphicsScene::addCompass(QPointF center) setModified(true); } +void UBGraphicsScene::addCache() +{ + UBGraphicsCache* cache = new UBGraphicsCache(); + mTools << cache; + QGraphicsView* view; + + if(UBApplication::applicationController->displayManager()->hasDisplay()) + { + view = (QGraphicsView*)(UBApplication::boardController->displayView()); + } + else + { + view = (QGraphicsView*)(UBApplication::boardController->controlView()); + } + addItem(cache); + cache->setVisible(true); + cache->setSelected(true); + UBApplication::boardController->notifyCache(true); +} void UBGraphicsScene::addMask() { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 5a5ffe2e..9e622e39 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -46,6 +46,7 @@ class UBGraphicsCurtainItem; class UBGraphicsStroke; class UBMagnifierParams; class UBMagnifier; +class UBGraphicsCache; const double PI = 4.0 * atan(1.0); @@ -172,6 +173,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void addMagnifier(UBMagnifierParams params); void addMask(); + void addCache(); class SceneViewState { @@ -247,6 +249,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem static qreal toolOffsetCompass; static qreal toolOffsetCurtain; static qreal toolOffsetTriangle; + static qreal toolOffsetCache; QSet tools(){ return mTools;} @@ -358,6 +361,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem //int mMesure1Ms, mMesure2Ms; + bool mHasCache; UBMagnifier *magniferControlViewWidget; UBMagnifier *magniferDisplayViewWidget; }; diff --git a/src/gui/UBCachePropertiesWidget.cpp b/src/gui/UBCachePropertiesWidget.cpp new file mode 100644 index 00000000..6b7062f8 --- /dev/null +++ b/src/gui/UBCachePropertiesWidget.cpp @@ -0,0 +1,317 @@ +#include +#include +#include +#include + +#include "UBCachePropertiesWidget.h" + +#include "core/UBApplication.h" +#include "board/UBBoardController.h" +#include "domain/UBGraphicsScene.h" + +static QVector mCaches; + +UBCachePropertiesWidget::UBCachePropertiesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) + , mpLayout(NULL) + , mpCachePropertiesLabel(NULL) + , mpColorLabel(NULL) + , mpShapeLabel(NULL) + , mpSizeLabel(NULL) + , mpColor(NULL) + , mpSquareButton(NULL) + , mpCircleButton(NULL) + , mpCloseButton(NULL) + , mpSizeSlider(NULL) + , mpColorLayout(NULL) + , mpShapeLayout(NULL) + , mpSizeLayout(NULL) + , mpCloseLayout(NULL) + , mpProperties(NULL) + , mpPropertiesLayout(NULL) + , mpCurrentCache(NULL) +{ + setObjectName(name); + setAttribute(Qt::WA_StyledBackground, true); + setStyleSheet(UBApplication::globalStyleSheet()); + + mName = "CachePropWidget"; + mIconToLeft = QPixmap(":images/cache_open.png"); + mIconToRight = QPixmap(":images/cache_close.png"); + setContentsMargins(10, 10, 10, 10); + + // Build the UI + mpLayout = new QVBoxLayout(); + setLayout(mpLayout); + + // Title + mpCachePropertiesLabel = new QLabel(tr("Cache Properties"), this); + mpCachePropertiesLabel->setObjectName("DockPaletteWidgetTitle"); + mpLayout->addWidget(mpCachePropertiesLabel, 0); + + // Properties Box + mpProperties = new QWidget(this); + mpProperties->setObjectName("DockPaletteWidgetBox"); + mpLayout->addWidget(mpProperties, 1); + mpPropertiesLayout = new QVBoxLayout(); + mpProperties->setLayout(mpPropertiesLayout); + + + // Color + mpColorLayout = new QHBoxLayout(); + mpColorLabel = new QLabel(tr("Color:"), mpProperties); + mpColor = new QPushButton(mpProperties); + mpColor->setObjectName("DockPaletteWidgetButton"); + // TODO: Check in the document if the page has a color and assign it to this cache + // else set the black color by default + updateCacheColor(Qt::black); + mpColorLayout->addWidget(mpColorLabel, 0); + mpColorLayout->addWidget(mpColor, 0); + mpColorLayout->addStretch(1); + mpPropertiesLayout->addLayout(mpColorLayout, 0); + + // Shape + mpShapeLayout = new QHBoxLayout(); + mpShapeLabel = new QLabel(tr("Shape:"), mpProperties); + mpSquareButton = new QPushButton(mpProperties); + mpSquareButton->setIcon(QIcon(":images/cache_square.png")); + mpSquareButton->setObjectName("DockPaletteWidgetButton"); + mpSquareButton->setCheckable(true); + mpCircleButton = new QPushButton(mpProperties); + mpCircleButton->setIcon(QIcon(":images/cache_circle.png")); + mpCircleButton->setObjectName("DockPaletteWidgetButton"); + mpCircleButton->setCheckable(true); + mpShapeLayout->addWidget(mpShapeLabel, 0); + mpShapeLayout->addWidget(mpSquareButton, 0); + mpShapeLayout->addWidget(mpCircleButton, 0); + mpShapeLayout->addStretch(1); + mpPropertiesLayout->addLayout(mpShapeLayout, 0); + + // TODO: Check in the document which shape is saved and check the corresponding button + mpCircleButton->setChecked(true); + + // Shape Size + mpSizeLayout = new QHBoxLayout(); + mpSizeLabel = new QLabel(tr("Size:"), mpProperties); + mpSizeSlider = new QSlider(Qt::Horizontal, mpProperties); + mpSizeSlider->setMinimumHeight(20); + mpSizeSlider->setMinimum(0); + mpSizeSlider->setMaximum(MAX_SHAPE_WIDTH); + mpSizeLayout->addWidget(mpSizeLabel, 0); + mpSizeLayout->addWidget(mpSizeSlider, 1); + mpPropertiesLayout->addLayout(mpSizeLayout, 0); + + // Close + mpCloseLayout = new QHBoxLayout(); + mpCloseButton = new QPushButton(tr("Close"), mpProperties); + mpCloseButton->setObjectName("DockPaletteWidgetButton"); + mpCloseLayout->addWidget(mpCloseButton, 0); + mpCloseLayout->addStretch(1); + mpPropertiesLayout->addLayout(mpCloseLayout, 0); + + // Fill the empty space + mpPropertiesLayout->addStretch(1); + + // Connect signals / slots + connect(mpCloseButton, SIGNAL(clicked()), this, SLOT(onCloseClicked())); + connect(mpColor, SIGNAL(clicked()), this, SLOT(onColorClicked())); + connect(mpCircleButton, SIGNAL(clicked()), this, SLOT(updateShapeButtons())); + connect(mpSquareButton, SIGNAL(clicked()), this, SLOT(updateShapeButtons())); + connect(mpSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(onSizeChanged(int))); + connect(UBApplication::boardController, SIGNAL(pageChanged()), this, SLOT(updateCurrentCache())); +} + +UBCachePropertiesWidget::~UBCachePropertiesWidget() +{ + if(NULL != mpCachePropertiesLabel) + { + delete mpCachePropertiesLabel; + mpCachePropertiesLabel = NULL; + } + if(NULL != mpColorLabel) + { + delete mpColorLabel; + mpColorLabel = NULL; + } + if(NULL != mpShapeLabel) + { + delete mpShapeLabel; + mpShapeLabel = NULL; + } + if(NULL != mpSizeLabel) + { + delete mpSizeLabel; + mpSizeLabel = NULL; + } + if(NULL != mpColor) + { + delete mpColor; + mpColor = NULL; + } + if(NULL != mpSquareButton) + { + delete mpSquareButton; + mpSquareButton = NULL; + } + if(NULL != mpCircleButton) + { + delete mpCircleButton; + mpCircleButton = NULL; + } + if(NULL != mpCloseButton) + { + delete mpCloseButton; + mpCloseButton = NULL; + } + if(NULL != mpSizeSlider) + { + delete mpSizeSlider; + mpSizeSlider = NULL; + } + if(NULL != mpColorLayout) + { + delete mpColorLayout; + mpColorLayout = NULL; + } + if(NULL != mpShapeLayout) + { + delete mpShapeLayout; + mpShapeLayout = NULL; + } + if(NULL != mpSizeLayout) + { + delete mpSizeLayout; + mpSizeLayout = NULL; + } + if(NULL != mpCloseLayout) + { + delete mpCloseLayout; + mpCloseLayout = NULL; + } + if(NULL != mpPropertiesLayout) + { + delete mpPropertiesLayout; + mpPropertiesLayout = NULL; + } + if(NULL != mpProperties) + { + delete mpProperties; + mpProperties = NULL; + } + if(NULL != mpLayout) + { + delete mpLayout; + mpLayout = NULL; + } +} + +void UBCachePropertiesWidget::onCloseClicked() +{ + // Remove the current cache from the list + mCaches.remove(mCaches.indexOf(mpCurrentCache)); + + // Remove the cache from the board + UBApplication::boardController->activeScene()->removeItem(mpCurrentCache); + mpCurrentCache = NULL; + + if(mCaches.empty()) + { + emit cacheListEmpty(); + } +} + +void UBCachePropertiesWidget::updateCacheColor(QColor color) +{ + mActualColor = color; + + // Update the color on the color button + QPixmap pix(32, 32); + QPainter p; + + p.begin(&pix); + + p.setBackground(Qt::transparent); + p.setBrush(color); // The current color + p.drawRect(0, 0, 32, 32); + + p.end(); + + mpColor->setIcon(QIcon(pix)); + + if(NULL != mpCurrentCache) + { + mpCurrentCache->setMaskColor(mActualColor); + } +} + +void UBCachePropertiesWidget::onColorClicked() +{ + // Show the color picker + QColor newColor = QColorDialog::getColor(mActualColor,this); + updateCacheColor(newColor); +} + +void UBCachePropertiesWidget::updateShapeButtons() +{ + if(mpCircleButton->hasFocus()) + { + mActualShape = eMaskShape_Circle; + mpSquareButton->setChecked(false); + } + else if(mpSquareButton->hasFocus()) + { + mActualShape = eMaskShap_Rectangle; + mpCircleButton->setChecked(false); + } + + if(NULL != mpCurrentCache) + { + mpCurrentCache->setMaskShape(mActualShape); + } +} + +void UBCachePropertiesWidget::updateCurrentCache() +{ + // Get the current page cache + QList items = UBApplication::boardController->activeScene()->items(); + foreach(QGraphicsItem* it, items) + { + if("Cache" == it->data(Qt::UserRole).toString()) + { + setEnabled(true); + mpCurrentCache = dynamic_cast(it); + if((NULL != mpCurrentCache) && (!mCaches.contains(mpCurrentCache))) + { + mCaches.append(mpCurrentCache); + } + + // Update the values of the cache properties + mpSizeSlider->setValue(mpCurrentCache->shapeWidth()); + updateCacheColor(mpCurrentCache->maskColor()); + switch(mpCurrentCache->maskshape()) + { + case eMaskShape_Circle: + mpCircleButton->setChecked(true); + mpSquareButton->setChecked(false); + break; + case eMaskShap_Rectangle: + mpCircleButton->setChecked(false); + mpSquareButton->setChecked(true); + break; + } + + return; + } + } + + // If we fall here, that means that this page has no cache + mpCurrentCache = NULL; + setDisabled(true); +} + +void UBCachePropertiesWidget::onSizeChanged(int newSize) +{ + if(NULL != mpCurrentCache) + { + mpCurrentCache->setShapeWidth(newSize); + } +} diff --git a/src/gui/UBCachePropertiesWidget.h b/src/gui/UBCachePropertiesWidget.h new file mode 100644 index 00000000..e347b033 --- /dev/null +++ b/src/gui/UBCachePropertiesWidget.h @@ -0,0 +1,60 @@ +#ifndef UBCACHEPROPERTIESWIDGET_H +#define UBCACHEPROPERTIESWIDGET_H + +#include +#include +#include +#include +#include +#include +#include + +#include "UBDockPaletteWidget.h" +#include "tools/UBGraphicsCache.h" + +#define MAX_SHAPE_WIDTH 200 + +class UBCachePropertiesWidget : public UBDockPaletteWidget +{ + Q_OBJECT +public: + UBCachePropertiesWidget(QWidget* parent=0, const char* name="UBCachePropertiesWidget"); + ~UBCachePropertiesWidget(); + +public slots: + void updateCurrentCache(); + +signals: + void cacheListEmpty(); + +private slots: + void onCloseClicked(); + void updateCacheColor(QColor color); + void onColorClicked(); + void updateShapeButtons(); + void onSizeChanged(int newSize); + +private: + QVBoxLayout* mpLayout; + QLabel* mpCachePropertiesLabel; + QLabel* mpColorLabel; + QLabel* mpShapeLabel; + QLabel* mpSizeLabel; + QPushButton* mpColor; + QPushButton* mpSquareButton; + QPushButton* mpCircleButton; + QPushButton* mpCloseButton; + QSlider* mpSizeSlider; + QHBoxLayout* mpColorLayout; + QHBoxLayout* mpShapeLayout; + QHBoxLayout* mpSizeLayout; + QHBoxLayout* mpCloseLayout; + QWidget* mpProperties; + QVBoxLayout* mpPropertiesLayout; + QColor mActualColor; + eMaskShape mActualShape; + UBGraphicsCache* mpCurrentCache; + +}; + +#endif // UBCACHEPROPERTIESWIDGET_H diff --git a/src/gui/UBDockPalette.cpp b/src/gui/UBDockPalette.cpp index b342bc6a..1eaece2d 100644 --- a/src/gui/UBDockPalette.cpp +++ b/src/gui/UBDockPalette.cpp @@ -515,9 +515,12 @@ int UBDockPalette::customMargin() void UBDockPalette::addTabWidget(UBDockPaletteWidget *widget) { - mTabWidgets.append(widget); - mpStackWidget->addWidget(widget); - update(); + if(!mTabWidgets.contains(widget)) + { + mTabWidgets.append(widget); + mpStackWidget->addWidget(widget); + update(); + } } void UBDockPalette::removeTab(const QString &widgetName) diff --git a/src/gui/UBDockPalette.h b/src/gui/UBDockPalette.h index 34c3ee2b..438eab7b 100644 --- a/src/gui/UBDockPalette.h +++ b/src/gui/UBDockPalette.h @@ -61,6 +61,7 @@ public: eUBDockOrientation orientation(); void setOrientation(eUBDockOrientation orientation); void setTabsOrientation(eUBDockTabOrientation orientation); + void showTabWidget(int tabIndex); virtual void mouseMoveEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event); @@ -127,7 +128,7 @@ private slots: private: void tabClicked(int tabIndex); int tabSpacing(); - void showTabWidget(int tabIndex); + void toggleCollapseExpand(); }; diff --git a/src/gui/UBPageNavigationWidget.cpp b/src/gui/UBPageNavigationWidget.cpp index 8c4c20c6..6f598fd0 100644 --- a/src/gui/UBPageNavigationWidget.cpp +++ b/src/gui/UBPageNavigationWidget.cpp @@ -127,6 +127,9 @@ void UBPageNavigationWidget::changeCurrentPage() { // Display the selected page UBApplication::boardController->setActiveDocumentScene(mNavigator->currentDoc(), iPage); + + // emit here the signal to indicate that page change + UBApplication::boardController->notifyPageChanged(); } } diff --git a/src/gui/UBRightPalette.cpp b/src/gui/UBRightPalette.cpp index c7f8a765..ee673ac8 100644 --- a/src/gui/UBRightPalette.cpp +++ b/src/gui/UBRightPalette.cpp @@ -12,8 +12,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include "core/UBApplication.h" +#include "board/UBBoardController.h" + #include "UBRightPalette.h" + UBRightPalette::UBRightPalette(QWidget *parent, const char *name):UBDockPalette(parent) , mpLibWidget(NULL) { @@ -25,8 +29,16 @@ UBRightPalette::UBRightPalette(QWidget *parent, const char *name):UBDockPalette( resize(UBSettings::settings()->libPaletteWidth->get().toInt(), parentWidget()->height()); mpLayout->setContentsMargins(2*border() + customMargin(), customMargin(), customMargin(), customMargin()); + // Add the tab widgets mpLibWidget = new UBLibWidget(this); addTabWidget(mpLibWidget); + + mpCachePropWidget = new UBCachePropertiesWidget(this); + mpCachePropWidget->hide(); + + // Connect signals/slots + connect(UBApplication::boardController, SIGNAL(cacheEnabled()), this, SLOT(onCacheEnabled())); + connect(mpCachePropWidget, SIGNAL(cacheListEmpty()), this, SLOT(onCacheDisabled())); } UBRightPalette::~UBRightPalette() @@ -36,6 +48,11 @@ UBRightPalette::~UBRightPalette() delete mpLibWidget; mpLibWidget = NULL; } + if(NULL != mpCachePropWidget) + { + delete mpCachePropWidget; + mpCachePropWidget = NULL; + } } UBLibWidget* UBRightPalette::libWidget() @@ -62,12 +79,39 @@ void UBRightPalette::resizeEvent(QResizeEvent *event) emit resized(); } -/** - * \brief Update the maximum width - */ void UBRightPalette::updateMaxWidth() { setMaximumWidth((int)((parentWidget()->width() * 2)/3)); setMaximumHeight(parentWidget()->height()); setMinimumHeight(parentWidget()->height()); } + +void UBRightPalette::onCacheEnabled() +{ + if(mpCachePropWidget->isHidden()) + { + mpCachePropWidget->setVisible(true); + // Add the cache tab + addTabWidget(mpCachePropWidget); + } + + // Set the cache of the current page as the active one for the properties widget + mpCachePropWidget->updateCurrentCache(); + + // Show the cache properties widget + for(int i = 0; i < mTabWidgets.size(); i++) + { + if((NULL != mTabWidgets.at(i)) && ("CachePropWidget" == mTabWidgets.at(i)->name())) + { + showTabWidget(i); + break; + } + } + +} + +void UBRightPalette::onCacheDisabled() +{ + removeTab(mpCachePropWidget->name()); + mpCachePropWidget->hide(); +} diff --git a/src/gui/UBRightPalette.h b/src/gui/UBRightPalette.h index 7d99cd4c..6919acf9 100644 --- a/src/gui/UBRightPalette.h +++ b/src/gui/UBRightPalette.h @@ -17,6 +17,7 @@ #include "UBDockPalette.h" #include "UBLibWidget.h" +#include "UBCachePropertiesWidget.h" class UBRightPalette : public UBDockPalette { @@ -35,8 +36,13 @@ protected: void mouseMoveEvent(QMouseEvent *event); void resizeEvent(QResizeEvent *event); +private slots: + void onCacheEnabled(); + void onCacheDisabled(); + private: UBLibWidget* mpLibWidget; + UBCachePropertiesWidget* mpCachePropWidget; }; #endif // UBRIGHTPALETTE_H diff --git a/src/gui/gui.pri b/src/gui/gui.pri index ba025bdf..3dae376c 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -41,7 +41,8 @@ HEADERS += src/gui/UBThumbnailView.h \ src/gui/UBRightPalette.h \ src/gui/UBPageNavigationWidget.h \ src/gui/UBLibWidget.h \ - src/gui/UBMagnifer.h + src/gui/UBMagnifer.h \ + src/gui/UBCachePropertiesWidget.h SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBFloatingPalette.cpp \ @@ -85,7 +86,8 @@ SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBRightPalette.cpp \ src/gui/UBPageNavigationWidget.cpp \ src/gui/UBLibWidget.cpp \ - src/gui/UBMagnifer.cpp + src/gui/UBMagnifer.cpp \ + src/gui/UBCachePropertiesWidget.cpp win32 { diff --git a/src/tools/UBGraphicsCache.cpp b/src/tools/UBGraphicsCache.cpp index b226132c..9895b3c4 100644 --- a/src/tools/UBGraphicsCache.cpp +++ b/src/tools/UBGraphicsCache.cpp @@ -33,6 +33,7 @@ UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem() QRect boardRect = UBApplication::boardController->displayView()->rect(); setRect(-15*boardRect.width(), -15*boardRect.height(), 30*boardRect.width(), 30*boardRect.height()); setZValue(CACHE_ZVALUE); + setData(Qt::UserRole, QVariant("Cache")); } UBGraphicsCache::~UBGraphicsCache() @@ -62,6 +63,7 @@ QColor UBGraphicsCache::maskColor() void UBGraphicsCache::setMaskColor(QColor color) { mMaskColor = color; + update(); } eMaskShape UBGraphicsCache::maskshape() @@ -72,6 +74,7 @@ eMaskShape UBGraphicsCache::maskshape() void UBGraphicsCache::setMaskShape(eMaskShape shape) { mMaskShape = shape; + update(); } void UBGraphicsCache::init() @@ -139,4 +142,5 @@ int UBGraphicsCache::shapeWidth() void UBGraphicsCache::setShapeWidth(int width) { mShapeWidth = width; + update(); } diff --git a/src/tools/UBToolsManager.cpp b/src/tools/UBToolsManager.cpp index 5fb516e8..e536bc2c 100644 --- a/src/tools/UBToolsManager.cpp +++ b/src/tools/UBToolsManager.cpp @@ -65,6 +65,17 @@ UBToolsManager::UBToolsManager(QObject *parent) mToolsIcon.insert(magnifier.id,":/images/toolPalette/magnifierTool.png"); mDescriptors << magnifier; +// -------------------------------------------------------------------------------- +// DO NOT ERASE THIS COMMENTED CODE! IT WILL BE UNCOMMENTED DURING THE NEXT DAYS!!! +// -------------------------------------------------------------------------------- + cache.id = "uniboardTool://uniboard.mnemis.com/cache"; + cache.icon = QPixmap(":/images/toolPalette/cacheTool.png"); + cache.label = tr("Cache"); + cache.version = "1.0"; + mToolsIcon.insert(cache.id, ":/images/toolPalette/cacheTool.png"); + mDescriptors << cache; +// -------------------------------------------------------------------------------- + } UBToolsManager::~UBToolsManager() diff --git a/src/tools/UBToolsManager.h b/src/tools/UBToolsManager.h index df87db8a..3ad3ccf1 100644 --- a/src/tools/UBToolsManager.h +++ b/src/tools/UBToolsManager.h @@ -79,6 +79,7 @@ class UBToolsManager : public QObject UBToolDescriptor mask; UBToolDescriptor triangle; UBToolDescriptor magnifier; + UBToolDescriptor cache; QString iconFromToolId(QString id) { return mToolsIcon.value(id);}