From 1e25ccf979146584ad502dab5a486b06b5f2b4e4 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Mon, 27 Jun 2011 09:49:00 +0200 Subject: [PATCH 01/13] Removed connection to a wrong slot --- src/core/UBApplicationController.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 601d5ba1..de5f2cfe 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -87,11 +87,10 @@ UBApplicationController::UBApplicationController(UBBoardView *pControlView, UBBo , this, SLOT(addCapturedPixmap(const QPixmap &, bool, const QUrl&))); networkAccessManager = new QNetworkAccessManager (this); - connect (networkAccessManager, SIGNAL (finished (QNetworkReply*)), this, SLOT (downloadJsonFinished (QNetworkReply*))); QTimer::singleShot (1000, this, SLOT (checkUpdateAtLaunch())); #ifdef Q_WS_X11 -// mMainWindow->setStyleSheet("QToolButton { font-size: 11px}"); + mMainWindow->setStyleSheet("QToolButton { font-size: 11px}"); #endif } From f776cdbab621bc2e732bcfa2c77a3a7cc64b841e Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Mon, 27 Jun 2011 11:22:53 +0200 Subject: [PATCH 02/13] changed Uniboard with Sankore --- src/adaptors/UBExportDocument.cpp | 2 +- src/adaptors/UBImportVirtualPrinter.cpp | 8 ++-- src/adaptors/UBMetadataDcSubsetAdaptor.cpp | 2 +- src/adaptors/UBSvgSubsetAdaptor.cpp | 2 +- src/adaptors/UBWebPublisher.cpp | 2 +- .../publishing/UBDocumentPublisher.cpp | 6 +-- src/board/UBBoardController.cpp | 2 +- src/core/UBDocumentManager.cpp | 4 +- src/core/UBPersistenceManager.cpp | 2 +- src/document/UBDocumentController.cpp | 2 +- src/frameworks/UBPlatformUtils_mac.mm | 42 +++++++++---------- src/podcast/UBPodcastController.cpp | 2 +- src/web/browser/WBWebView.cpp | 2 +- 13 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/adaptors/UBExportDocument.cpp b/src/adaptors/UBExportDocument.cpp index af2ba68f..962b9502 100644 --- a/src/adaptors/UBExportDocument.cpp +++ b/src/adaptors/UBExportDocument.cpp @@ -99,5 +99,5 @@ QString UBExportDocument::exportExtention() QString UBExportDocument::exportName() { - return tr("Export to Uniboard Format"); + return tr("Export to Sankore Format"); } diff --git a/src/adaptors/UBImportVirtualPrinter.cpp b/src/adaptors/UBImportVirtualPrinter.cpp index ca7919c0..95fecea4 100644 --- a/src/adaptors/UBImportVirtualPrinter.cpp +++ b/src/adaptors/UBImportVirtualPrinter.cpp @@ -132,7 +132,7 @@ void UBImportVirtualPrinter::cleanUp(const QFile& pFile, const QString& pPdfFile UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QString& pGroup) { - UBApplication::showMessage(tr("Importing Uniboard printer file ...")); + UBApplication::showMessage(tr("Importing Sankore printer file ...")); UBDocumentProxy *document = 0; QString pdfFilename = pdfFileName(pFile); @@ -159,7 +159,7 @@ UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QS if (!document) { - UBApplication::showMessage(tr("Error while importing Uniboard printer file.")); + UBApplication::showMessage(tr("Error while importing Sankore printer file.")); } cleanUp(pFile, pdfFilename, emfFileNames(pFile)); @@ -170,7 +170,7 @@ UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QS bool UBImportVirtualPrinter::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) { - UBApplication::showMessage(tr("Importing Uniboard printer file ...")); + UBApplication::showMessage(tr("Importing Sankore printer file ...")); bool result = false; QString pdfFilename = pdfFileName(pFile); @@ -183,7 +183,7 @@ bool UBImportVirtualPrinter::addFileToDocument(UBDocumentProxy* pDocument, const if (!result) { - UBApplication::showMessage(tr("Error while importing Uniboard printer file.")); + UBApplication::showMessage(tr("Error while importing Sankore printer file.")); } cleanUp(pFile, pdfFilename, emfFileNames(pFile)); diff --git a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp index 72a54552..4bb689e5 100644 --- a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp +++ b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp @@ -204,7 +204,7 @@ QMap UBMetadataDcSubsetAdaptor::load(QString pPath) if (xml.hasError()) { - qWarning() << "error parsing uniboard metadata.rdf file " << xml.errorString(); + qWarning() << "error parsing sankore metadata.rdf file " << xml.errorString(); } } diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index ef825ab9..e8de8cf9 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -770,7 +770,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() if (mXmlReader.hasError()) { - qWarning() << "error parsing uniboard file " << mXmlReader.errorString(); + qWarning() << "error parsing Sankore file " << mXmlReader.errorString(); } if (scene) diff --git a/src/adaptors/UBWebPublisher.cpp b/src/adaptors/UBWebPublisher.cpp index 80133b34..36b3c08c 100644 --- a/src/adaptors/UBWebPublisher.cpp +++ b/src/adaptors/UBWebPublisher.cpp @@ -28,7 +28,7 @@ UBWebPublisher::~UBWebPublisher() QString UBWebPublisher::exportName() { - return tr("Publish Document on Uniboard Web"); + return tr("Publish Document on Sankore Web"); } diff --git a/src/adaptors/publishing/UBDocumentPublisher.cpp b/src/adaptors/publishing/UBDocumentPublisher.cpp index 3d98d92d..bd09c1a5 100644 --- a/src/adaptors/publishing/UBDocumentPublisher.cpp +++ b/src/adaptors/publishing/UBDocumentPublisher.cpp @@ -676,7 +676,7 @@ void UBDocumentPublisher::sendZipToUniboardWeb(const QString& zipFilePath, const if(!zipFile.open(QIODevice::ReadOnly)) { - qWarning() << "Cannot open file" << zipFilePath << "for upload to Uniboard Web"; + qWarning() << "Cannot open file" << zipFilePath << "for upload to Sankore Web"; return; } @@ -712,7 +712,7 @@ void UBDocumentPublisher::uploadProgress(qint64 bytesSent, qint64 bytesTotal) int percentage = (((qreal)bytesSent / (qreal)bytesTotal ) * 100); if (bytesSent < bytesTotal) - UBApplication::showMessage(tr("Upload to Uniboard Web in progress %1 %").arg(percentage), true); + UBApplication::showMessage(tr("Upload to Sankore Web in progress %1 %").arg(percentage), true); else UBApplication::showMessage(tr("Sending document ..."), true); @@ -727,7 +727,7 @@ void UBDocumentPublisher::postZipUploadResponse(bool success, const QByteArray& } else { - qWarning() << "error uploading document to Uniboard Web" << QString::fromUtf8(payload); + qWarning() << "error uploading document to Sankore Web" << QString::fromUtf8(payload); QString errorMessage = QString::fromUtf8(payload); diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 69b4d262..f8043fd0 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -956,7 +956,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString } else { - UBApplication::showMessage(tr("Flash is not supported on Uniboard Linux")); + UBApplication::showMessage(tr("Flash is not supported on Sankore Linux")); } } else if (mimeType.startsWith("application/pdf")) diff --git a/src/core/UBDocumentManager.cpp b/src/core/UBDocumentManager.cpp index e041ecc9..402009a5 100644 --- a/src/core/UBDocumentManager.cpp +++ b/src/core/UBDocumentManager.cpp @@ -29,6 +29,7 @@ #include "UBPersistenceManager.h" #include "core/memcheck.h" +#include "../adaptors/UBExportWeb.h" UBDocumentManager* UBDocumentManager::sDocumentManager = 0; @@ -53,9 +54,10 @@ UBDocumentManager::UBDocumentManager(QObject *parent) UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this); mExportAdaptors.append(exportFullPdf); - UBExportDocument* exportDocument = new UBExportDocument(this); mExportAdaptors.append(exportDocument); + UBExportWeb* exportWeb = new UBExportWeb(this); + mExportAdaptors.append(exportWeb); UBImportDocument* documentImport = new UBImportDocument(this); mImportAdaptors.append(documentImport); diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 2729c10e..14752c4c 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -1000,7 +1000,7 @@ void UBPersistenceManager::checkIfDocumentRepositoryExists() QMessageBox::question( QApplication::activeWindow(), tr("Document Repository Loss"), - tr("Uniboard has lost access to the document repository '%1'. Unfortunately the application must shut down to avoid data corruption. Latest changes may be lost as well.").arg(humanPath), + tr("Sankore has lost access to the document repository '%1'. Unfortunately the application must shut down to avoid data corruption. Latest changes may be lost as well.").arg(humanPath), QMessageBox::Yes); UBApplication::quit(); diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 34600c79..bd0e48b8 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1446,7 +1446,7 @@ bool UBDocumentController::isOKToOpenDocument(UBDocumentProxy* proxy) else { if (QMessageBox::question( 0, tr("Open Document"), - tr("The document '%1' has been generated with a newer version of Uniboard (%2). By opening it, you may lose some information. Do you want to proceed?") + tr("The document '%1' has been generated with a newer version of Sankore (%2). By opening it, you may lose some information. Do you want to proceed?") .arg(proxy->metaData(UBSettings::documentName).toString()) .arg(docVersion), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index 828e0292..c92a6746 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -46,8 +46,8 @@ void UBPlatformUtils::init() NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *currentPath = [[NSBundle mainBundle] pathForResource:@"Save PDF to Uniboard" ofType:@"workflow"]; - NSString *installedPath = [[[@"~/Library/PDF Services" stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Save PDF to Uniboard"] stringByAppendingPathExtension:@"workflow"]; + NSString *currentPath = [[NSBundle mainBundle] pathForResource:@"Save PDF to Sankore" ofType:@"workflow"]; + NSString *installedPath = [[[@"~/Library/PDF Services" stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Save PDF to Sankore"] stringByAppendingPathExtension:@"workflow"]; NSString *currentVersion = bundleShortVersion([NSBundle bundleWithPath:currentPath]); NSString *installedVersion = bundleShortVersion([NSBundle bundleWithPath:installedPath]); @@ -59,7 +59,7 @@ void UBPlatformUtils::init() BOOL copyOK = [fileManager copyPath:currentPath toPath:installedPath handler:nil]; if (!copyOK) { - qWarning("Could not install the 'Save PDF to Uniboard' workflow"); + qWarning("Could not install the 'Save PDF to Sankore' workflow"); } } @@ -364,25 +364,25 @@ KEYBT* createKeyBt(const UCKeyboardLayout* keyLayout, int vkk) void UBPlatformUtils::initializeKeyboardLayouts() { - CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceIsEnableCapable, kTISPropertyInputSourceIsSelectCapable }; - const void* values[] = { kTISCategoryKeyboardInputSource, kCFBooleanTrue, kCFBooleanTrue }; - CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 3, NULL, NULL); - CFArrayRef kbds = TISCreateInputSourceList(dict, false); - - int count = CFArrayGetCount(kbds); + CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceIsEnableCapable, kTISPropertyInputSourceIsSelectCapable }; + const void* values[] = { kTISCategoryKeyboardInputSource, kCFBooleanTrue, kCFBooleanTrue }; + CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 3, NULL, NULL); + CFArrayRef kbds = TISCreateInputSourceList(dict, false); + + int count = CFArrayGetCount(kbds); QList result; - + for(int i=0; ivideoFileExtension(); + videoFileName = mPodcastRecordingPath + "/" + tr("Sankore Cast") + "." + mVideoEncoder->videoFileExtension(); } videoFileName = UBFileSystemUtils::nextAvailableFileName(videoFileName, " "); diff --git a/src/web/browser/WBWebView.cpp b/src/web/browser/WBWebView.cpp index 7d9c3f74..16bf05d2 100644 --- a/src/web/browser/WBWebView.cpp +++ b/src/web/browser/WBWebView.cpp @@ -151,7 +151,7 @@ void WBWebPage::handleUnsupportedContent(QNetworkReply *reply) if (isPDF) { QMessageBox messageBox(mainWindow()); - messageBox.setText(tr("Download PDF Document: would you prefer to download the PDF file or add it to the current Uniboard document?")); + messageBox.setText(tr("Download PDF Document: would you prefer to download the PDF file or add it to the current Sankore document?")); messageBox.addButton(tr("Download"), QMessageBox::AcceptRole); QAbstractButton *addButton = From ed5b1906d0fb824cf04798000499359c77bd8787 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 29 Jun 2011 15:13:50 +0200 Subject: [PATCH 03/13] fixed sankore issue 160 on windows --- src/board/UBLibraryController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp index adb0108d..ba603e3f 100644 --- a/src/board/UBLibraryController.cpp +++ b/src/board/UBLibraryController.cpp @@ -724,7 +724,7 @@ UBLibElement* UBLibElement::trashElement() if (trashElement) return trashElement; - trashElement = new UBLibElement(eUBLibElementType_Folder, UBSettings::trashLibraryPaletteDirPath(), QObject::tr("Trash", "Pictures category element")); + trashElement = new UBLibElement(eUBLibElementType_Folder, QUrl::fromLocalFile(UBSettings::trashLibraryPaletteDirPath()), QObject::tr("Trash", "Pictures category element")); QImage *categoryImage = new QImage(":images/libpalette/TrashCategory.svg"); trashElement->setThumbnail(categoryImage); trashElement->setMoveable(false); From 575970e4e209ed554a086636816b50d5df8079ec Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Wed, 29 Jun 2011 15:23:37 +0200 Subject: [PATCH 04/13] Triangle graphics tool --- src/adaptors/UBSvgSubsetAdaptor.cpp | 50 ++++ src/adaptors/UBSvgSubsetAdaptor.h | 3 + src/core/main.cpp | 5 + src/domain/UBGraphicsScene.cpp | 10 +- src/domain/UBGraphicsScene.h | 1 + src/frameworks/UBCoreGraphicsScene.cpp | 1 - src/tools/UBAbstractDrawRuler.cpp | 126 ++++++++ src/tools/UBAbstractDrawRuler.h | 62 +++- src/tools/UBGraphicsProtractor.cpp | 120 ++++---- src/tools/UBGraphicsProtractor.h | 30 +- src/tools/UBGraphicsRuler.cpp | 392 +++++++++---------------- src/tools/UBGraphicsRuler.h | 67 ++--- src/tools/UBGraphicsTriangle.cpp | 224 +++++++++++++- src/tools/UBGraphicsTriangle.h | 60 +++- 14 files changed, 755 insertions(+), 396 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index ef825ab9..616b74b7 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -26,6 +26,7 @@ #include "tools/UBGraphicsCompass.h" #include "tools/UBGraphicsProtractor.h" #include "tools/UBGraphicsCurtainItem.h" +#include "tools/UBGraphicsTriangle.h" #include "document/UBDocumentProxy.h" @@ -644,6 +645,16 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(protractor); scene->registerTool(protractor); } + } + else if (mXmlReader.name() == "protractor") + { + UBGraphicsTriangle *triangle = triangleFromSvg(); + + if (triangle) + { + scene->addItem(triangle); + scene->registerTool(triangle); + } } else if (mXmlReader.name() == "foreignObject") { @@ -2556,7 +2567,46 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg() return protractor; } +UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() +{ + UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); + + triangle->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetTriangle); + triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); + + graphicsItemFromSvg(triangle); + + //QStringRef angle = mXmlReader.attributes().value(mNamespaceUri, "angle"); + //if (!angle.isNull()) + //{ + // protractor->setAngle(angle.toString().toFloat()); + //} + + //QStringRef markerAngle = mXmlReader.attributes().value(mNamespaceUri, "marker-angle"); + //if (!markerAngle.isNull()) + //{ + // protractor->setMarkerAngle(markerAngle.toString().toFloat()); + //} + + QStringRef svgX = mXmlReader.attributes().value("x"); + QStringRef svgY = mXmlReader.attributes().value("y"); + QStringRef svgWidth = mXmlReader.attributes().value("width"); + QStringRef svgHeight = mXmlReader.attributes().value("height"); + + UBGraphicsTriangle::UBGraphicsTriangleOrientation orientation = + UBGraphicsTriangle::orientationFromStr((mXmlReader.attributes().value("orientation"))); + if (!svgX.isNull() && !svgY.isNull() && !svgWidth.isNull() && !svgHeight.isNull()) + { + triangle->setRect(svgX.toString().toFloat(), svgY.toString().toFloat() + , svgWidth.toString().toFloat(), svgHeight.toString().toFloat(), + orientation); + } + + triangle->setVisible(true); + + return triangle; +} void UBSvgSubsetAdaptor::convertPDFObjectsToImages(UBDocumentProxy* proxy) { diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index b38bbf29..12bc1812 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -31,6 +31,7 @@ class UBGraphicsScene; class UBDocumentProxy; class UBGraphicsStroke; class UBPersistenceManager; +class UBGraphicsTriangle; class UBSvgSubsetAdaptor { @@ -118,6 +119,8 @@ class UBSvgSubsetAdaptor UBGraphicsProtractor* protractorFromSvg(); + UBGraphicsTriangle* triangleFromSvg(); + void graphicsItemFromSvg(QGraphicsItem* gItem); QXmlStreamReader mXmlReader; diff --git a/src/core/main.cpp b/src/core/main.cpp index a608a466..06bbad5f 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -54,9 +54,14 @@ void ub_message_output(QtMsgType type, const char *msg) { int main(int argc, char *argv[]) { + +// Uncomment next section to have memory leaks information +// tracing in VC++ debug mode under Windows +/* #if defined(_MSC_VER) && defined(_DEBUG) _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif +*/ Q_INIT_RESOURCE(sankore); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index f950f29c..5e35e63d 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -56,6 +56,7 @@ qreal UBGraphicsScene::toolLayerStart = 10000000.0; qreal UBGraphicsScene::toolOffsetRuler = 100; qreal UBGraphicsScene::toolOffsetProtractor = 100; +qreal UBGraphicsScene::toolOffsetTriangle = 100; qreal UBGraphicsScene::toolOffsetCompass = 100; qreal UBGraphicsScene::toolOffsetEraser = 200; @@ -125,7 +126,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) UBGraphicsScene::~UBGraphicsScene() { - int a = 13; // NOOP } @@ -1411,9 +1411,9 @@ void UBGraphicsScene::addProtractor(QPointF center) void UBGraphicsScene::addTriangle(QPointF center) { - // Protractor -/* - UBGraphicsTriangle* protractor = new UBGraphicsTriangle(); // mem : owned and destroyed by the scene + // Triangle + + UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); // mem : owned and destroyed by the scene mTools << triangle; triangle->setZValue(toolLayerStart + toolOffsetProtractor); @@ -1425,7 +1425,7 @@ void UBGraphicsScene::addTriangle(QPointF center) triangle->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y()); triangle->setVisible(true); - setModified(true);*/ + setModified(true); } diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 6b32fb2b..7c27ff06 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -235,6 +235,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem static qreal toolOffsetProtractor; static qreal toolOffsetCompass; static qreal toolOffsetCurtain; + static qreal toolOffsetTriangle; QSet tools(){ return mTools;} diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index 109bd002..28ccc2db 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -12,7 +12,6 @@ UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent) : QGraphicsScene ( parent ) { - int a = 13; //NOOP } diff --git a/src/tools/UBAbstractDrawRuler.cpp b/src/tools/UBAbstractDrawRuler.cpp index b96d823b..5297d99a 100644 --- a/src/tools/UBAbstractDrawRuler.cpp +++ b/src/tools/UBAbstractDrawRuler.cpp @@ -1,11 +1,137 @@ #include "UBAbstractDrawRuler.h" +#include +#include "core/UB.h" +#include "gui/UBResources.h" +#include "domain/UBGraphicsScene.h" +#include "board/UBDrawingController.h" +#include "core/UBApplication.h" +#include "board/UBBoardController.h" #include "core/memcheck.h" + +const QColor UBAbstractDrawRuler::sLightBackgroundMiddleFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency); +const QColor UBAbstractDrawRuler::sLightBackgroundEdgeFillColor = QColor(0xc3, 0xc3, 0xc3, sFillTransparency); +const QColor UBAbstractDrawRuler::sLightBackgroundDrawColor = QColor(0x33, 0x33, 0x33, sDrawTransparency); +const QColor UBAbstractDrawRuler::sDarkBackgroundMiddleFillColor = QColor(0xb5, 0xb5, 0xb5, sFillTransparency); +const QColor UBAbstractDrawRuler::sDarkBackgroundEdgeFillColor = QColor(0xdd, 0xdd, 0xdd, sFillTransparency); +const QColor UBAbstractDrawRuler::sDarkBackgroundDrawColor = QColor(0xff, 0xff, 0xff, sDrawTransparency); + UBAbstractDrawRuler::UBAbstractDrawRuler() + : mResizing(false) + , mRotating(false) + , mShowButtons(false) + , mAntiScaleRatio(1.0) {} +void UBAbstractDrawRuler::create(QGraphicsItem& item) +{ + item.setFlag(QGraphicsItem::ItemIsMovable, true); + item.setFlag(QGraphicsItem::ItemIsSelectable, true); + item.setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + + item.setAcceptsHoverEvents(true); + + mCloseSvgItem = new QGraphicsSvgItem(":/images/closeTool.svg", &item); + mCloseSvgItem->setVisible(false); + mCloseSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + + mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", &item); + mRotateSvgItem->setVisible(false); + mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + + updateResizeCursor(item); +} + UBAbstractDrawRuler::~UBAbstractDrawRuler() +{ +} + +void UBAbstractDrawRuler::updateResizeCursor(QGraphicsItem &item) +{ + QPixmap pix(":/images/cursors/resize.png"); + QTransform itemTransform = item.sceneTransform(); + QRectF itemRect = item.boundingRect(); + QPointF topLeft = itemTransform.map(itemRect.topLeft()); + QPointF topRight = itemTransform.map(itemRect.topRight()); + QLineF topLine(topLeft, topRight); + qreal angle = topLine.angle(); + QTransform tr; + tr.rotate(- angle); + QCursor resizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); + mResizeCursor = resizeCursor; +} + + +QCursor UBAbstractDrawRuler::moveCursor() const +{ + return Qt::SizeAllCursor; +} + +QCursor UBAbstractDrawRuler::resizeCursor() const +{ + return mResizeCursor; +} + +QCursor UBAbstractDrawRuler::rotateCursor() const +{ + return UBResources::resources()->rotateCursor; +} + +QCursor UBAbstractDrawRuler::closeCursor() const +{ + return Qt::ArrowCursor; +} + +QCursor UBAbstractDrawRuler::drawRulerLineCursor() const +{ + return UBResources::resources()->drawLineRulerCursor; +} + +QColor UBAbstractDrawRuler::drawColor() const +{ + return scene()->isDarkBackground() ? sDarkBackgroundDrawColor : sLightBackgroundDrawColor; +} + +QColor UBAbstractDrawRuler::middleFillColor() const +{ + return scene()->isDarkBackground() ? sDarkBackgroundMiddleFillColor : sLightBackgroundMiddleFillColor; +} + +QColor UBAbstractDrawRuler::edgeFillColor() const +{ + return scene()->isDarkBackground() ? sDarkBackgroundEdgeFillColor : sLightBackgroundEdgeFillColor; +} + +QFont UBAbstractDrawRuler::font() const +{ + QFont font("Arial"); + font.setPixelSize(16); + return font; +} + +void UBAbstractDrawRuler::StartLine(const QPointF& position, qreal width) +{} +void UBAbstractDrawRuler::DrawLine(const QPointF& position, qreal width) +{} +void UBAbstractDrawRuler::EndLine() {} + + +void UBAbstractDrawRuler::paint() +{ + mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); + QTransform antiScaleTransform; + antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio); + + mCloseSvgItem->setTransform(antiScaleTransform); + mCloseSvgItem->setPos(closeButtonRect().topLeft()); + + mRotateSvgItem->setTransform(antiScaleTransform); + mRotateSvgItem->setPos(rotateButtonRect().topLeft()); + +} + + diff --git a/src/tools/UBAbstractDrawRuler.h b/src/tools/UBAbstractDrawRuler.h index ae2f423f..f89e493b 100644 --- a/src/tools/UBAbstractDrawRuler.h +++ b/src/tools/UBAbstractDrawRuler.h @@ -3,18 +3,72 @@ #include class UBGraphicsScene; +class QGraphicsSvgItem; class UBAbstractDrawRuler : public QObject { - Q_OBJECT; + Q_OBJECT public: UBAbstractDrawRuler(); ~UBAbstractDrawRuler(); - virtual void StartLine(const QPointF& position, qreal width) = 0; - virtual void DrawLine(const QPointF& position, qreal width) = 0; - virtual void EndLine() = 0; + void create(QGraphicsItem& item); + + virtual void StartLine(const QPointF& position, qreal width); + virtual void DrawLine(const QPointF& position, qreal width); + virtual void EndLine(); + protected: + + void paint(); + + virtual UBGraphicsScene* scene() const = 0; + + virtual void rotateAroundTopLeftOrigin(qreal angle) = 0; + + virtual QPointF topLeftOrigin() const = 0; + virtual QRectF resizeButtonRect() const = 0; + virtual QRectF closeButtonRect() const = 0; + virtual QRectF rotateButtonRect() const = 0; + + void updateResizeCursor(QGraphicsItem &item); + + bool mResizing; + bool mRotating; + bool mShowButtons; + QGraphicsSvgItem* mCloseSvgItem; + QGraphicsSvgItem* mRotateSvgItem; + QCursor mResizeCursor; + qreal mAntiScaleRatio; + + QPointF startDrawPosition; + + QCursor moveCursor() const; + QCursor resizeCursor() const; + QCursor rotateCursor() const; + QCursor closeCursor() const; + QCursor drawRulerLineCursor() const; + + QColor drawColor() const; + QColor middleFillColor() const; + QColor edgeFillColor() const; + QFont font() const; + + static const QColor sLightBackgroundEdgeFillColor; + static const QColor sLightBackgroundMiddleFillColor; + static const QColor sLightBackgroundDrawColor; + static const QColor sDarkBackgroundEdgeFillColor; + static const QColor sDarkBackgroundMiddleFillColor; + static const QColor sDarkBackgroundDrawColor; + + static const int sLeftEdgeMargin = 10; + static const int sMinLength = 150; + static const int sDegreeToQtAngleUnit = 16; + static const int sRotationRadius = 15; + static const int sPixelsPerMillimeter = 5; + static const int sFillTransparency = 127; + static const int sDrawTransparency = 192; + static const int sRoundingRadius = sLeftEdgeMargin / 2; }; diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index 206096d8..566feaf8 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -16,15 +16,7 @@ #include "core/memcheck.h" -const int UBGraphicsProtractor::sFillTransparency = 127; -const int UBGraphicsProtractor::sDrawTransparency = 192; const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350); -const QColor UBGraphicsProtractor::sFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency); -const QColor UBGraphicsProtractor::sFillColorCenter = QColor(0xbe, 0xbe, 0xbe, sFillTransparency); -const QColor UBGraphicsProtractor::sDrawColor = QColor(32, 32, 32, sDrawTransparency); -const QColor UBGraphicsProtractor::sDarkBackgroundFillColor = QColor(0xb5, 0xb5, 0xb5, sFillTransparency); -const QColor UBGraphicsProtractor::sDarkBackgroundFillColorCenter = QColor(0xde, 0xde, 0xde, sFillTransparency); -const QColor UBGraphicsProtractor::sDarkBackgroundDrawColor = QColor(255, 255, 255, sDrawTransparency); UBGraphicsProtractor::UBGraphicsProtractor() : QGraphicsEllipseItem(sDefaultRect) @@ -34,46 +26,32 @@ UBGraphicsProtractor::UBGraphicsProtractor() , mSpan(180) , mStartAngle(0) , mScaleFactor(1) - , mCloseSvgItem(0) , mResetSvgItem(0) , mResizeSvgItem(0) - , mRotateSvgItem(0) , mMarkerSvgItem(0) { - setFlag(QGraphicsItem::ItemIsMovable, true); - setFlag(QGraphicsItem::ItemIsSelectable, true); - setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - setAcceptsHoverEvents(true); - setCacheMode(QGraphicsItem::DeviceCoordinateCache); + create(*this); + + setCacheMode(QGraphicsItem::DeviceCoordinateCache); setStartAngle(0); setSpanAngle(180 * 16); - mCloseSvgItem = new QGraphicsSvgItem(":/images/closeTool.svg", this); - mCloseSvgItem->setVisible(false); - mCloseSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - mCloseSvgItem->setPos(closeButtonBounds().topLeft()); - mResetSvgItem = new QGraphicsSvgItem(":/images/resetTool.svg", this); mResetSvgItem->setVisible(false); mResetSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - mResetSvgItem->setPos(resetButtonBounds().topLeft()); + mResetSvgItem->setPos(resetButtonRect().topLeft()); mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeTool.svg", this); mResizeSvgItem->setVisible(false); mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - mResizeSvgItem->setPos(resizeButtonBounds().topLeft()); - - mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateProtractor.svg", this); - mRotateSvgItem->setVisible(false); - mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - mRotateSvgItem->setPos(rotateButtonBounds().topLeft()); + mResizeSvgItem->setPos(resizeButtonRect().topLeft()); mMarkerSvgItem = new QGraphicsSvgItem(":/images/angleMarker.svg", this); mMarkerSvgItem->setVisible(false); mMarkerSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); - mMarkerSvgItem->setPos(markerButtonBounds().topLeft()); + mMarkerSvgItem->setPos(markerButtonRect().topLeft()); scale(1.5, 1.5); } @@ -120,9 +98,9 @@ QRectF UBGraphicsProtractor::boundingRect() const qreal centerX = center.x(); qreal centerY = center.y(); - QRectF bounds = resizeButtonBounds().adjusted(centerX, centerY, centerX, centerY); - bounds = bounds.united(closeButtonBounds().adjusted(centerX, centerY, centerX, centerY)); - bounds = bounds.united(resetButtonBounds().adjusted(centerX, centerY, centerX, centerY)); + QRectF bounds = resizeButtonRect().adjusted(centerX, centerY, centerX, centerY); + bounds = bounds.united(closeButtonRect().adjusted(centerX, centerY, centerX, centerY)); + bounds = bounds.united(resetButtonRect().adjusted(centerX, centerY, centerX, centerY)); QTransform t; t.translate(centerX, centerY); @@ -140,21 +118,21 @@ QPainterPath UBGraphicsProtractor::shape() const { QPainterPath path = QGraphicsEllipseItem::shape(); QPainterPath buttonPath; - QRectF markerBounds = markerButtonBounds(); + QRectF markerRect = markerButtonRect(); QPointF center = rect().center(); qreal centerX = center.x(); qreal centerY = center.y(); - buttonPath.addRect(resizeButtonBounds().adjusted(centerX, centerY, centerX, centerY)); - if(!resizeButtonBounds().contains(markerBounds)) + buttonPath.addRect(resizeButtonRect().adjusted(centerX, centerY, centerX, centerY)); + if(!resizeButtonRect().contains(markerRect)) { - buttonPath.addRect(markerBounds.adjusted(centerX - markerBounds.left() * 2 - markerBounds.width(), centerY - , centerX - markerBounds.left() * 2 - markerBounds.width(), centerY)); - buttonPath.addRect(markerBounds.adjusted(centerX, centerY, centerX, centerY)); + buttonPath.addRect(markerRect.adjusted(centerX - markerRect.left() * 2 - markerRect.width(), centerY + , centerX - markerRect.left() * 2 - markerRect.width(), centerY)); + buttonPath.addRect(markerRect.adjusted(centerX, centerY, centerX, centerY)); } - buttonPath.addRect(closeButtonBounds().adjusted(centerX, centerY, centerX, centerY)); - buttonPath.addRect(resetButtonBounds().adjusted(centerX, centerY, centerX, centerY)); + buttonPath.addRect(closeButtonRect().adjusted(centerX, centerY, centerX, centerY)); + buttonPath.addRect(resetButtonRect().adjusted(centerX, centerY, centerX, centerY)); QTransform t; t.translate(centerX, centerY); t.rotate(-mStartAngle); @@ -323,7 +301,7 @@ qreal UBGraphicsProtractor::antiScale() const } -QRectF UBGraphicsProtractor::resetButtonBounds () const +QRectF UBGraphicsProtractor::resetButtonRect () const { qreal antiSc = antiScale(); @@ -336,7 +314,7 @@ QRectF UBGraphicsProtractor::resetButtonBounds () const } -QRectF UBGraphicsProtractor::closeButtonBounds () const +QRectF UBGraphicsProtractor::closeButtonRect () const { qreal antiSc = antiScale(); @@ -352,7 +330,7 @@ QRectF UBGraphicsProtractor::closeButtonBounds () const } -QRectF UBGraphicsProtractor::resizeButtonBounds () const +QRectF UBGraphicsProtractor::resizeButtonRect () const { qreal antiSc = antiScale(); @@ -442,41 +420,41 @@ void UBGraphicsProtractor::paintButtons(QPainter *painter) qreal antiSc = antiScale(); qreal scale = buttonSizeReference().width() / mCloseSvgItem->boundingRect().width(); - mCloseSvgItem->setPos(closeButtonBounds().topLeft() + rect().center()); + mCloseSvgItem->setPos(closeButtonRect().topLeft() + rect().center()); mCloseSvgItem->resetTransform(); - mCloseSvgItem->translate(-closeButtonBounds().left(),-closeButtonBounds().top()); + mCloseSvgItem->translate(-closeButtonRect().left(),-closeButtonRect().top()); mCloseSvgItem->rotate(-mStartAngle); - mCloseSvgItem->translate(closeButtonBounds().left(), closeButtonBounds().top()); + mCloseSvgItem->translate(closeButtonRect().left(), closeButtonRect().top()); mCloseSvgItem->scale(scale * antiSc, scale * antiSc);//this do not impact the bounding box of thr svg item... - mResetSvgItem->setPos(resetButtonBounds().topLeft() + rect().center()); + mResetSvgItem->setPos(resetButtonRect().topLeft() + rect().center()); mResetSvgItem->resetTransform(); - mResetSvgItem->translate(-resetButtonBounds().left(), -resetButtonBounds().top()); + mResetSvgItem->translate(-resetButtonRect().left(), -resetButtonRect().top()); mResetSvgItem->rotate(-mStartAngle); - mResetSvgItem->translate(resetButtonBounds().left(), resetButtonBounds().top()); + mResetSvgItem->translate(resetButtonRect().left(), resetButtonRect().top()); mResetSvgItem->scale(scale * antiSc, scale * antiSc);//this do not impact the bounding box of thr svg item... - mResizeSvgItem->setPos(resizeButtonBounds().topLeft() + rect().center()); + mResizeSvgItem->setPos(resizeButtonRect().topLeft() + rect().center()); mResizeSvgItem->resetTransform(); - mResizeSvgItem->translate(-resizeButtonBounds().left(), -resizeButtonBounds().top()); + mResizeSvgItem->translate(-resizeButtonRect().left(), -resizeButtonRect().top()); mResizeSvgItem->rotate(-mStartAngle); - mResizeSvgItem->translate(resizeButtonBounds().left(), resizeButtonBounds().top()); + mResizeSvgItem->translate(resizeButtonRect().left(), resizeButtonRect().top()); mResizeSvgItem->scale(scale * antiSc, scale * antiSc);//this do not impact the bounding box of thr svg item... - mRotateSvgItem->setPos(rotateButtonBounds().topLeft() + rect().center()); + mRotateSvgItem->setPos(rotateButtonRect().topLeft() + rect().center()); mRotateSvgItem->resetTransform(); - mRotateSvgItem->translate(-rotateButtonBounds().left(), -rotateButtonBounds().top()); + mRotateSvgItem->translate(-rotateButtonRect().left(), -rotateButtonRect().top()); mRotateSvgItem->rotate(-mStartAngle); - mRotateSvgItem->translate(rotateButtonBounds().left(), rotateButtonBounds().top()); + mRotateSvgItem->translate(rotateButtonRect().left(), rotateButtonRect().top()); mRotateSvgItem->scale(scale, scale);//this do not impact the bounding box of thr svg item... } qreal scale = markerSizeReference().width()/mMarkerSvgItem->boundingRect().width(); - mMarkerSvgItem->setPos(markerButtonBounds().topLeft() + rect().center()); + mMarkerSvgItem->setPos(markerButtonRect().topLeft() + rect().center()); mMarkerSvgItem->resetTransform(); - mMarkerSvgItem->translate(-markerButtonBounds().left(), -markerButtonBounds().top()); + mMarkerSvgItem->translate(-markerButtonRect().left(), -markerButtonRect().top()); mMarkerSvgItem->rotate(- mStartAngle - mCurrentAngle); - mMarkerSvgItem->translate(markerButtonBounds().left(), markerButtonBounds().top()); + mMarkerSvgItem->translate(markerButtonRect().left(), markerButtonRect().top()); mMarkerSvgItem->scale(scale, scale);//this do not impact the bounding box of thr svg item... mCloseSvgItem->setVisible(mShowButtons); @@ -550,15 +528,15 @@ UBGraphicsProtractor::Tool UBGraphicsProtractor::toolFromPos(QPointF pos) t.rotate(mCurrentAngle); QPointF p2 = t.map(pos); - if(resizeButtonBounds().contains(p1)) + if(resizeButtonRect().contains(p1)) return Resize; - else if(closeButtonBounds().contains(p1)) + else if(closeButtonRect().contains(p1)) return Close; - else if(resetButtonBounds().contains(p1)) + else if(resetButtonRect().contains(p1)) return Reset; - else if(rotateButtonBounds().contains(p1)) + else if(rotateButtonRect().contains(p1)) return Rotate; - else if(markerButtonBounds().contains(p2)) + else if(markerButtonRect().contains(p2)) return MoveMarker; else if(line.length() <= radius()) return Move; @@ -572,15 +550,10 @@ UBGraphicsScene* UBGraphicsProtractor::scene() const return static_cast(QGraphicsEllipseItem::scene()); } -QColor UBGraphicsProtractor::drawColor() const -{ - return scene()->isDarkBackground() ? sDarkBackgroundDrawColor : sDrawColor; -} - QBrush UBGraphicsProtractor::fillBrush() const { - QColor fillColor = scene()->isDarkBackground() ? sDarkBackgroundFillColor : sFillColor; - QColor fillColorCenter = scene()->isDarkBackground() ? sDarkBackgroundFillColorCenter : sFillColorCenter; + QColor fillColor = edgeFillColor();// scene()->isDarkBackground() ? sDarkBackgroundFillColor : sFillColor; + QColor fillColorCenter = middleFillColor();//scene()->isDarkBackground() ? sDarkBackgroundFillColorCenter : sFillColorCenter; QColor transparentWhite = Qt::white; transparentWhite.setAlpha(scene()->isDarkBackground() ? sDrawTransparency : sFillTransparency); QRadialGradient radialGradient(rect().center(), radius(), rect().center()); @@ -608,3 +581,12 @@ UBItem* UBGraphicsProtractor::deepCopy() const return copy; } + + +void UBGraphicsProtractor::rotateAroundTopLeftOrigin(qreal angle) +{} + +QPointF UBGraphicsProtractor::topLeftOrigin() const +{ + return QPointF(rect().x(), rect().y()); +} diff --git a/src/tools/UBGraphicsProtractor.h b/src/tools/UBGraphicsProtractor.h index c6204b4c..7fd301c8 100644 --- a/src/tools/UBGraphicsProtractor.h +++ b/src/tools/UBGraphicsProtractor.h @@ -13,12 +13,12 @@ #include #include "core/UB.h" - +#include "tools/UBAbstractDrawRuler.h" #include "domain/UBItem.h" class UBGraphicsScene; -class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public UBItem +class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipseItem, public UBItem { Q_OBJECT; @@ -66,16 +66,15 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public Tool toolFromPos (QPointF pos); qreal antiScale () const; UBGraphicsScene* scene() const; - QColor drawColor() const; QBrush fillBrush() const; QSizeF buttonSizeReference () const{return QSizeF(radius() / 10, mCloseSvgItem->boundingRect().height() * radius()/(10 * mCloseSvgItem->boundingRect().width()));} QSizeF markerSizeReference () const{return QSizeF(radius() / 10, mMarkerSvgItem->boundingRect().height() * radius()/(10 * mMarkerSvgItem->boundingRect().width()));} - QRectF resetButtonBounds () const; - QRectF closeButtonBounds () const; - QRectF resizeButtonBounds () const; - QRectF rotateButtonBounds () const{return QRectF(buttonSizeReference().width() * 5.5, -buttonSizeReference().width() * 5, buttonSizeReference().width(), buttonSizeReference().width());} - QRectF markerButtonBounds () const{return QRectF(radius() + 3, -markerSizeReference().height() / 2 , markerSizeReference().width(), markerSizeReference().height());} + QRectF resetButtonRect () const; + QRectF closeButtonRect () const; + QRectF resizeButtonRect () const; + QRectF rotateButtonRect () const{return QRectF(buttonSizeReference().width() * 5.5, -buttonSizeReference().width() * 5, buttonSizeReference().width(), buttonSizeReference().width());} + QRectF markerButtonRect () const{return QRectF(radius() + 3, -markerSizeReference().height() / 2 , markerSizeReference().width(), markerSizeReference().height());} inline qreal radius () const{return rect().height() / 2 - 20;} // Members @@ -87,21 +86,14 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public qreal mStartAngle; qreal mScaleFactor; - QGraphicsSvgItem* mCloseSvgItem; QGraphicsSvgItem* mResetSvgItem; QGraphicsSvgItem* mResizeSvgItem; - QGraphicsSvgItem* mRotateSvgItem; QGraphicsSvgItem* mMarkerSvgItem; - static const int sFillTransparency; - static const int sDrawTransparency; - static const QRectF sDefaultRect; - static const QColor sFillColor; - static const QColor sFillColorCenter; - static const QColor sDrawColor; - static const QColor sDarkBackgroundFillColor; - static const QColor sDarkBackgroundFillColorCenter; - static const QColor sDarkBackgroundDrawColor; + static const QRectF sDefaultRect; + + virtual void rotateAroundTopLeftOrigin(qreal angle); + virtual QPointF topLeftOrigin() const; }; #endif /* UBGRAPHICSPROTRACTOR_H_ */ diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 8d3b3d2a..cfc952ef 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -18,45 +18,19 @@ #include "core/memcheck.h" const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, 96); -const QColor UBGraphicsRuler::sLightBackgroundMiddleFillColor = QColor(0x72, 0x72, 0x72, sFillTransparency); -const QColor UBGraphicsRuler::sLightBackgroundEdgeFillColor = QColor(0xc3, 0xc3, 0xc3, sFillTransparency); -const QColor UBGraphicsRuler::sLightBackgroundDrawColor = QColor(0x33, 0x33, 0x33, sDrawTransparency); -const QColor UBGraphicsRuler::sDarkBackgroundMiddleFillColor = QColor(0xb5, 0xb5, 0xb5, sFillTransparency); -const QColor UBGraphicsRuler::sDarkBackgroundEdgeFillColor = QColor(0xdd, 0xdd, 0xdd, sFillTransparency); -const QColor UBGraphicsRuler::sDarkBackgroundDrawColor = QColor(0xff, 0xff, 0xff, sDrawTransparency); UBGraphicsRuler::UBGraphicsRuler() : QGraphicsRectItem() - , mResizing(false) - , mRotating(false) - , mShowButtons(false) - , mCloseSvgItem(0) - , mRotateSvgItem(0) - , mResizeSvgItem(0) - , mAntiScaleRatio(1.0) { - setRect(sDefaultRect); - setFlag(QGraphicsItem::ItemIsMovable, true); - setFlag(QGraphicsItem::ItemIsSelectable, true); - setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - - setAcceptsHoverEvents(true); - - mCloseSvgItem = new QGraphicsSvgItem(":/images/closeTool.svg", this); - mCloseSvgItem->setVisible(false); - mCloseSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - - mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this); - mRotateSvgItem->setVisible(false); - mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeRuler.svg", this); + mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeRuler.svg", this); mResizeSvgItem->setVisible(false); mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - updateResizeCursor(); + + create(*this); } UBGraphicsRuler::~UBGraphicsRuler() @@ -83,22 +57,15 @@ void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *s Q_UNUSED(styleOption); Q_UNUSED(widget); - mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); - QTransform antiScaleTransform; - antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio); - - mCloseSvgItem->setTransform(antiScaleTransform); - mCloseSvgItem->setPos(closeButtonRect().topLeft()); - - mRotateSvgItem->setTransform(antiScaleTransform); - mRotateSvgItem->setPos(rotateButtonRect().topLeft()); + UBAbstractDrawRuler::paint(); - QTransform antiScaleTransform2; + QTransform antiScaleTransform2; qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0; antiScaleTransform2.scale(ratio, 1.0); mResizeSvgItem->setTransform(antiScaleTransform2); mResizeSvgItem->setPos(resizeButtonRect().topLeft()); + painter->setPen(drawColor()); painter->drawRoundedRect(rect(), sRoundingRadius, sRoundingRadius); fillBackground(painter); @@ -120,168 +87,6 @@ QVariant UBGraphicsRuler::itemChange(GraphicsItemChange change, const QVariant & return QGraphicsRectItem::itemChange(change, value); } - -void UBGraphicsRuler::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if (event->pos().x() > resizeButtonRect().left()) - { - mResizing = true; - event->accept(); - } - else if (rotateButtonRect().contains(event->pos())) - { - mRotating = true; - event->accept(); - } - else - { - mResizeSvgItem->setVisible(false); - mRotateSvgItem->setVisible(false); - QGraphicsRectItem::mousePressEvent(event); - } - mResizeSvgItem->setVisible(mShowButtons && mResizing); - mRotateSvgItem->setVisible(mShowButtons && mRotating); - mCloseSvgItem->setVisible(false); -} - -void UBGraphicsRuler::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if (!mResizing && !mRotating) - { - QGraphicsRectItem::mouseMoveEvent(event); - } - else - { - if (mResizing) - { - QPointF delta = event->pos() - event->lastPos(); - if (rect().width() + delta.x() < sMinLength) - delta.setX(sMinLength - rect().width()); - setRect(QRectF(rect().topLeft(), QSizeF(rect().width() + delta.x(), rect().height()))); - } - else - { - QLineF currentLine(topLeftOrigin(), event->pos()); - QLineF lastLine(topLeftOrigin(), event->lastPos()); - rotateAroundTopLeftOrigin(currentLine.angleTo(lastLine)); - } - - event->accept(); - } -} - -void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - if (mResizing) - { - mResizing = false; - event->accept(); - } - else if (mRotating) - { - mRotating = false; - updateResizeCursor(); - update(QRectF(topLeftOrigin(), QSizeF(sRotationRadius, sRotationRadius))); - event->accept(); - } - else if (closeButtonRect().contains(event->pos())) - { - hide(); - - emit hidden(); - - event->accept(); - } - else - { - QGraphicsRectItem::mouseReleaseEvent(event); - } - - if (scene()) - scene()->setModified(true); -} - -void UBGraphicsRuler::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - QObject* obj = new QObject(); - UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); - - if (currentTool == UBStylusTool::Selector) - { - mCloseSvgItem->setParentItem(this); - mResizeSvgItem->setParentItem(this); - mRotateSvgItem->setParentItem(this); - - mShowButtons = true; - mCloseSvgItem->setVisible(mShowButtons); - mResizeSvgItem->setVisible(mShowButtons); - mRotateSvgItem->setVisible(mShowButtons); - if (event->pos().x() >= resizeButtonRect().left()) - { - setCursor(resizeCursor()); - } - else - { - if (closeButtonRect().contains(event->pos())) - setCursor(closeCursor()); - else if (rotateButtonRect().contains(event->pos())) - setCursor(rotateCursor()); - else - setCursor(moveCursor()); - } - event->accept(); - update(); - } - else if (UBDrawingController::drawingController()->isDrawingTool()) - { - setCursor(drawRulerLineCursor()); - UBDrawingController::drawingController()->mActiveRuler = this; - event->accept(); - } -} - -void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - mShowButtons = false; - setCursor(Qt::ArrowCursor); - mCloseSvgItem->setVisible(mShowButtons); - mResizeSvgItem->setVisible(mShowButtons); - mRotateSvgItem->setVisible(mShowButtons); - UBDrawingController::drawingController()->mActiveRuler = NULL; - event->accept(); - update(); -} - -void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); - - if (currentTool == UBStylusTool::Selector) - { - mCloseSvgItem->setVisible(mShowButtons); - mResizeSvgItem->setVisible(mShowButtons); - mRotateSvgItem->setVisible(mShowButtons); - if (event->pos().x() >= resizeButtonRect().left()) - { - setCursor(resizeCursor()); - } - else - { - if (closeButtonRect().contains(event->pos())) - setCursor(closeCursor()); - else if (rotateButtonRect().contains(event->pos())) - setCursor(rotateCursor()); - else - setCursor(moveCursor()); - } - event->accept(); - } - else if (currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Marker) - { - event->accept(); - } -} - void UBGraphicsRuler::fillBackground(QPainter *painter) { QRectF rect1(rect().topLeft(), QSizeF(rect().width(), rect().height() / 4)); @@ -365,25 +170,6 @@ QPointF UBGraphicsRuler::topLeftOrigin() const return QPointF(rect().x() + sLeftEdgeMargin, rect().y()); } -QCursor UBGraphicsRuler::moveCursor() const -{ - return Qt::SizeAllCursor; -} - -QCursor UBGraphicsRuler::resizeCursor() const -{ - return mResizeCursor; -} - -QCursor UBGraphicsRuler::rotateCursor() const -{ - return UBResources::resources()->rotateCursor; -} - -QCursor UBGraphicsRuler::closeCursor() const -{ - return Qt::ArrowCursor; -} QRectF UBGraphicsRuler::resizeButtonRect() const { @@ -440,51 +226,165 @@ QRectF UBGraphicsRuler::rotateButtonRect() const return QRectF(rotateRectTopLeft, rotateRectSize); } -UBGraphicsScene* UBGraphicsRuler::scene() const +void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { - return static_cast(QGraphicsRectItem::scene()); + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); + + if (currentTool == UBStylusTool::Selector) + { + mCloseSvgItem->setVisible(mShowButtons); + mResizeSvgItem->setVisible(mShowButtons); + mRotateSvgItem->setVisible(mShowButtons); + if (resizeButtonRect().contains(event->pos())) + setCursor(resizeCursor()); + else if (closeButtonRect().contains(event->pos())) + setCursor(closeCursor()); + else if (rotateButtonRect().contains(event->pos())) + setCursor(rotateCursor()); + else + setCursor(moveCursor()); + + event->accept(); + } + else if (currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Marker) + { + event->accept(); + } } -QColor UBGraphicsRuler::drawColor() const +void UBGraphicsRuler::mousePressEvent(QGraphicsSceneMouseEvent *event) { - return scene()->isDarkBackground() ? sDarkBackgroundDrawColor : sLightBackgroundDrawColor; + if (event->pos().x() > resizeButtonRect().left()) + { + mResizing = true; + event->accept(); + } + else if (rotateButtonRect().contains(event->pos())) + { + mRotating = true; + event->accept(); + } + else + { + mResizeSvgItem->setVisible(false); + mRotateSvgItem->setVisible(false); + QGraphicsItem::mousePressEvent(event); + } + mResizeSvgItem->setVisible(mShowButtons && mResizing); + mRotateSvgItem->setVisible(mShowButtons && mRotating); + mCloseSvgItem->setVisible(false); } -QColor UBGraphicsRuler::middleFillColor() const +void UBGraphicsRuler::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - return scene()->isDarkBackground() ? sDarkBackgroundMiddleFillColor : sLightBackgroundMiddleFillColor; + if (!mResizing && !mRotating) + { + QGraphicsItem::mouseMoveEvent(event); + } + else + { + if (mResizing) + { + QPointF delta = event->pos() - event->lastPos(); + if (rect().width() + delta.x() < sMinLength) + delta.setX(sMinLength - rect().width()); + setRect(QRectF(rect().topLeft(), QSizeF(rect().width() + delta.x(), rect().height()))); + } + else + { + QLineF currentLine(topLeftOrigin(), event->pos()); + QLineF lastLine(topLeftOrigin(), event->lastPos()); + rotateAroundTopLeftOrigin(currentLine.angleTo(lastLine)); + } + + event->accept(); + } } -QColor UBGraphicsRuler::edgeFillColor() const +void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - return scene()->isDarkBackground() ? sDarkBackgroundEdgeFillColor : sLightBackgroundEdgeFillColor; + if (mResizing) + { + mResizing = false; + event->accept(); + } + else if (mRotating) + { + mRotating = false; + updateResizeCursor(*this); + update(QRectF(topLeftOrigin(), QSizeF(sRotationRadius, sRotationRadius))); + event->accept(); + } + else if (closeButtonRect().contains(event->pos())) + { + hide(); + emit hidden(); + event->accept(); + } + else + { + QGraphicsItem::mouseReleaseEvent(event); + } + + if (scene()) + scene()->setModified(true); } -QFont UBGraphicsRuler::font() const +void UBGraphicsRuler::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - QFont font("Arial"); - font.setPixelSize(16); - return font; + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); + + if (currentTool == UBStylusTool::Selector) + { + mCloseSvgItem->setParentItem(this); + mResizeSvgItem->setParentItem(this); + mRotateSvgItem->setParentItem(this); + + mShowButtons = true; + mCloseSvgItem->setVisible(mShowButtons); + mResizeSvgItem->setVisible(mShowButtons); + mRotateSvgItem->setVisible(mShowButtons); + if (event->pos().x() >= resizeButtonRect().left()) + { + setCursor(resizeCursor()); + } + else + { + if (closeButtonRect().contains(event->pos())) + setCursor(closeCursor()); + else if (rotateButtonRect().contains(event->pos())) + setCursor(rotateCursor()); + else + setCursor(moveCursor()); + } + event->accept(); + update(); + } + else if (UBDrawingController::drawingController()->isDrawingTool()) + { + setCursor(drawRulerLineCursor()); + UBDrawingController::drawingController()->mActiveRuler = this; + event->accept(); + } } -void UBGraphicsRuler::updateResizeCursor() +void UBGraphicsRuler::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - QPixmap pix(":/images/cursors/resize.png"); - QTransform itemTransform = sceneTransform(); - QRectF itemRect = boundingRect(); - QPointF topLeft = itemTransform.map(itemRect.topLeft()); - QPointF topRight = itemTransform.map(itemRect.topRight()); - QLineF topLine(topLeft, topRight); - qreal angle = topLine.angle(); - QTransform tr; - tr.rotate(- angle); - QCursor resizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); - mResizeCursor = resizeCursor; + mShowButtons = false; + setCursor(Qt::ArrowCursor); + mCloseSvgItem->setVisible(mShowButtons); + mResizeSvgItem->setVisible(mShowButtons); + mRotateSvgItem->setVisible(mShowButtons); + UBDrawingController::drawingController()->mActiveRuler = NULL; + event->accept(); + update(); } -QCursor UBGraphicsRuler::drawRulerLineCursor() const + + +UBGraphicsScene* UBGraphicsRuler::scene() const { - return UBResources::resources()->drawLineRulerCursor; + return static_cast(QGraphicsRectItem::scene()); } void UBGraphicsRuler::StartLine(const QPointF& scenePos, qreal width) diff --git a/src/tools/UBGraphicsRuler.h b/src/tools/UBGraphicsRuler.h index 9add46b8..99dcfdc8 100644 --- a/src/tools/UBGraphicsRuler.h +++ b/src/tools/UBGraphicsRuler.h @@ -44,70 +44,37 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu void hidden(); protected: + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); // Events - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); private: // Helpers - void fillBackground(QPainter *painter); - void paintGraduations(QPainter *painter); - void paintRotationCenter(QPainter *painter); - void rotateAroundTopLeftOrigin(qreal angle); - void updateResizeCursor(); - - QPointF topLeftOrigin() const; - QCursor moveCursor() const; - QCursor resizeCursor() const; - QCursor rotateCursor() const; - QCursor closeCursor() const; - QCursor drawRulerLineCursor() const; - QRectF resizeButtonRect() const; - QRectF closeButtonRect() const; - QRectF rotateButtonRect() const; - UBGraphicsScene* scene() const; - QColor drawColor() const; - QColor middleFillColor() const; - QColor edgeFillColor() const; - QFont font() const; + void fillBackground(QPainter *painter); + void paintGraduations(QPainter *painter); + void paintRotationCenter(QPainter *painter); + virtual void rotateAroundTopLeftOrigin(qreal angle); - int drawLineDirection; + QGraphicsSvgItem* mResizeSvgItem; - // Members - bool mResizing; - bool mRotating; - bool mShowButtons; - QGraphicsSvgItem* mCloseSvgItem; - QGraphicsSvgItem* mRotateSvgItem; - QGraphicsSvgItem* mResizeSvgItem; - QCursor mResizeCursor; - qreal mAntiScaleRatio; + virtual QPointF topLeftOrigin() const; + virtual QRectF resizeButtonRect() const; + virtual QRectF closeButtonRect() const; + virtual QRectF rotateButtonRect() const; + virtual UBGraphicsScene* scene() const; - QPointF startDrawPosition; + int drawLineDirection; // Constants static const QRect sDefaultRect; - static const int sLeftEdgeMargin = 10; - static const int sMinLength = 150; - static const int sDegreeToQtAngleUnit = 16; - static const int sRotationRadius = 15; - static const int sPixelsPerMillimeter = 5; - static const int sFillTransparency = 127; - static const int sDrawTransparency = 192; - static const int sRoundingRadius = sLeftEdgeMargin / 2; - static const QColor sLightBackgroundEdgeFillColor; - static const QColor sLightBackgroundMiddleFillColor; - static const QColor sLightBackgroundDrawColor; - static const QColor sDarkBackgroundEdgeFillColor; - static const QColor sDarkBackgroundMiddleFillColor; - static const QColor sDarkBackgroundDrawColor; }; #endif /* UBGRAPHICSRULER_H_ */ diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index 5786abc0..7c3f1a70 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -1,10 +1,232 @@ +#include +#include + #include "tools/UBGraphicsTriangle.h" +#include "core/UBApplication.h" +#include "board/UBBoardController.h" +#include "board/UBDrawingController.h" +#include "domain/UBGraphicsScene.h" + #include "core/memcheck.h" +const QRect UBGraphicsTriangle::sDefaultRect = QRect(0, 0, 800, 400); +const UBGraphicsTriangle::UBGraphicsTriangleOrientation UBGraphicsTriangle::sDefaultOrientation = +UBGraphicsTriangle::BottomLeft; + UBGraphicsTriangle::UBGraphicsTriangle() + :QGraphicsPolygonItem() { + setRect(sDefaultRect, sDefaultOrientation); + + create(*this); + + //updateResizeCursor(); } UBGraphicsTriangle::~UBGraphicsTriangle() -{} \ No newline at end of file +{ +} + +UBItem* UBGraphicsTriangle::deepCopy(void) const +{ + UBGraphicsTriangle* copy = new UBGraphicsTriangle(); + + copy->setPos(this->pos()); + copy->setPolygon(this->polygon()); + copy->setZValue(this->zValue()); + copy->setTransform(this->transform()); + + // TODO UB 4.7 ... complete all members ? + + return copy; + +} + +void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation) +{ + mRect.setCoords(x, y, x+w, y+h); + mOrientation = orientation; + + QPolygonF polygon; + polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h) << QPoint(x, y); + + QTransform t; + + switch(orientation) + { + case BottomLeft: + t.setMatrix(1, 0, 0, 0, 1, 0, 0, 0, 1); + break; + case BottomRight: + t.setMatrix(-1, 0, 0, 0, 1, 0, x, 0, 1); + break; + case TopLeft: + t.setMatrix(1, 0, 0, 0, -1, 0, 0, y, 1); + break; + case TopRight: + t.setMatrix(-1, 0, 0, 0, -1, 0, x, y, 1); + break; + } + + + /* + switch(orientation) + { + case BottomLeft: + polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h) << QPoint(x, y); + break; + case BottomRight: + polygon << QPointF(x, y + h) << QPoint(x + w, y + y) << QPoint(x + w, y) << QPoint(x, y + h); + break; + case TopLeft: + polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x + w, y) << QPoint(x, y); + break; + case TopRight: + polygon << QPointF(x, y) << QPoint(x + w, y + h) << QPoint(x+w, y) << QPoint(x, y ); + break; + } + */ + setPolygon(polygon); + setTransform(t); +} + +UBGraphicsScene* UBGraphicsTriangle::scene() const +{ + return static_cast(QGraphicsPolygonItem::scene()); +} + +void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) +{ + QPointF A1(mRect.x(), mRect.y()); + QPointF B1(mRect.x(), mRect.y() + mRect.height()); + QPointF C1(mRect.x() + mRect.width(), mRect.y() + mRect.height()); + + qreal d = 70; + qreal C = sqrt(mRect.width() * mRect.width() + mRect.height() * mRect.height()); + qreal L = (C * d + mRect.width() * d)/ mRect.height(); + qreal K = (C * d + mRect.height() * d)/ mRect.width(); + + qreal W1 = mRect.height() * d / C; + qreal H1 = mRect.width() * d / C; + + QPointF A2(mRect.x() + d, mRect.y() + K); + QPointF B2(mRect.x() + d, mRect.y() + mRect.height() - d); + QPointF C2(mRect.x() + mRect.width() - L, mRect.y() + mRect.height() - d); + + QPoint CC(mRect.x() + mRect.width() - L + W1, + mRect.y() + mRect.height() - d - H1); + + painter->setPen(Qt::NoPen); + + QPolygonF polygon; + + QLinearGradient gradient1(QPointF(A1.x(), 0), QPointF(A2.x(), 0)); + gradient1.setColorAt(0, edgeFillColor()); + gradient1.setColorAt(1, middleFillColor()); + painter->setBrush(gradient1); + polygon << A1 << A2 << B2 << B1; + painter->drawPolygon(polygon); + polygon.clear(); + + QLinearGradient gradient2(QPointF(0, B1.y()), QPointF(0, B2.y())); + gradient2.setColorAt(0, edgeFillColor()); + gradient2.setColorAt(1, middleFillColor()); + painter->setBrush(gradient2); + polygon << B1 << B2 << C2 << C1; + painter->drawPolygon(polygon); + polygon.clear(); + + QLinearGradient gradient3(CC, C2); + gradient3.setColorAt(0, edgeFillColor()); + gradient3.setColorAt(1, middleFillColor()); + painter->setBrush(gradient3); + polygon << C1 << C2 << A2 << A1; + painter->drawPolygon(polygon); + polygon.clear(); + + + painter->setBrush(Qt::NoBrush); + painter->setPen(drawColor()); + + polygon << A1 << B1 << C1; + painter->drawPolygon(polygon); + polygon.clear(); + + polygon << A2 << B2 << C2; + painter->drawPolygon(polygon); + + paintGraduations(painter); +} + +void UBGraphicsTriangle::paintGraduations(QPainter *painter) +{ + const int centimeterGraduationHeight = 15; + const int halfCentimeterGraduationHeight = 10; + const int millimeterGraduationHeight = 5; + const int millimetersPerCentimeter = 10; + const int millimetersPerHalfCentimeter = 5; + + painter->save(); + painter->setFont(font()); + QFontMetricsF fontMetrics(painter->font()); + for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++) + { + int graduationX = topLeftOrigin().x() + sPixelsPerMillimeter * millimeters; + int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ? + centimeterGraduationHeight : + ((0 == millimeters % millimetersPerHalfCentimeter) ? + halfCentimeterGraduationHeight : millimeterGraduationHeight); + + // Check that grad. line inside triangle + qreal lineY = rect().bottom() - rect().height()/rect().width()*(rect().width() - graduationX); + if (lineY >= topLeftOrigin().y() + rect().height() - graduationHeight) + break; + + painter->drawLine(QLine(graduationX, topLeftOrigin().y() + rect().height(), graduationX, topLeftOrigin().y() + rect().height() - graduationHeight)); + if (0 == millimeters % millimetersPerCentimeter) + { + QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); + int textXRight = graduationX + fontMetrics.width(text) / 2; + qreal textWidth = fontMetrics.width(text); + qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5; + int textY = rect().bottom() - 5 - centimeterGraduationHeight - textHeight; + + lineY = rect().bottom() - rect().height()/rect().width()*(rect().width() - textXRight); + + if (textXRight < rect().right() + && lineY < textY) + { + painter->drawText( + QRectF(graduationX - textWidth / 2, + textY, textWidth, textHeight), + Qt::AlignVCenter, text); + } + } + } + painter->restore(); +} + + +void UBGraphicsTriangle::rotateAroundTopLeftOrigin(qreal angle) +{} + +QPointF UBGraphicsTriangle::topLeftOrigin() const +{ + return QPointF(mRect.x() + sLeftEdgeMargin , mRect.y()); +} + +QRectF UBGraphicsTriangle::resizeButtonRect() const +{ + return QRectF(0,0,0,0); +} + +QRectF UBGraphicsTriangle::closeButtonRect() const +{ + return QRectF(0,0,0,0); +} + +QRectF UBGraphicsTriangle::rotateButtonRect() const +{ + return QRectF(0,0,0,0); +} diff --git a/src/tools/UBGraphicsTriangle.h b/src/tools/UBGraphicsTriangle.h index 4705ebc4..5cebf4a1 100644 --- a/src/tools/UBGraphicsTriangle.h +++ b/src/tools/UBGraphicsTriangle.h @@ -15,17 +15,75 @@ #include "core/UB.h" #include "domain/UBItem.h" +#include "tools/UBAbstractDrawRuler.h" class UBGraphicsScene; +class UBItem; -class UBGraphicsTriangle : public QObject, public QGraphicsPolygonItem, public UBItem +class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonItem, public UBItem { Q_OBJECT; public: UBGraphicsTriangle(); virtual ~UBGraphicsTriangle(); + + enum { Type = UBGraphicsItemType::TriangleItemType }; + + virtual int type() const + { + return Type; + } + + + virtual UBItem* deepCopy(void) const; + + enum UBGraphicsTriangleOrientation + { + BottomLeft = 0, + BottomRight, + TopLeft, + TopRight + }; + + static UBGraphicsTriangleOrientation orientationFromStr(QStringRef& str) + { + if (str == "BottomLeft") return BottomLeft; + if (str == "BottomRight") return BottomRight; + if (str == "TopLeft") return TopLeft; + if (str == "TopRight") return TopRight; + return sDefaultOrientation; + } + void setRect(const QRectF &rect, UBGraphicsTriangleOrientation orientation) + { + setRect(rect.x(), rect.y(), rect.width(), rect.height(), orientation); + } + void setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation); + QRectF rect() const {return mRect;} + + UBGraphicsScene* scene() const; + protected: + virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); + + virtual void rotateAroundTopLeftOrigin(qreal angle); + + virtual QPointF topLeftOrigin() const; + virtual QRectF resizeButtonRect() const; + virtual QRectF closeButtonRect() const; + virtual QRectF rotateButtonRect() const; + + + private: + + static const QRect sDefaultRect; + static const UBGraphicsTriangleOrientation sDefaultOrientation; + + void paintGraduations(QPainter *painter); + + + QRectF mRect; + UBGraphicsTriangleOrientation mOrientation; }; #endif /* UBGRAPHICSTRIANGLE_H_ */ From 30b87f02e78bb83a3cea2489ce20783b26b1d45a Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 30 Jun 2011 08:43:25 +0200 Subject: [PATCH 05/13] added web pubblication interface --- .../publishing/UBDocumentPublisher.cpp | 522 +++++++----------- src/adaptors/publishing/UBDocumentPublisher.h | 82 ++- src/board/UBBoardPaletteManager.cpp | 4 +- src/core/UBApplication.cpp | 20 +- src/core/UBApplication.h | 1 + src/core/UBApplicationController.cpp | 28 +- src/core/UBApplicationController.h | 4 +- src/core/UBDocumentManager.cpp | 6 +- src/document/UBDocumentController.h | 6 +- src/gui/UBMainWindow.cpp | 14 + src/gui/UBMainWindow.h | 5 + 11 files changed, 301 insertions(+), 391 deletions(-) diff --git a/src/adaptors/publishing/UBDocumentPublisher.cpp b/src/adaptors/publishing/UBDocumentPublisher.cpp index bd09c1a5..88c527e6 100644 --- a/src/adaptors/publishing/UBDocumentPublisher.cpp +++ b/src/adaptors/publishing/UBDocumentPublisher.cpp @@ -1,4 +1,4 @@ -#include "UBDocumentPublisher.h" + #include "UBDocumentPublisher.h" #include "frameworks/UBPlatformUtils.h" #include "frameworks/UBFileSystemUtils.h" @@ -10,6 +10,7 @@ #include "core/UBDocumentManager.h" #include "core/UBApplication.h" #include "core/UBPersistenceManager.h" +#include "core/UBApplicationController.h" #include "gui/UBMainWindow.h" @@ -27,163 +28,120 @@ #include "UBSvgSubsetRasterizer.h" #include "core/memcheck.h" +#include <../Trolltech/Qt-4.7.0/include/QtWebKit/qwebview.h> UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent) - : UBAbstractPublisher(parent) - , mSourceDocument(pDocument) - , mPublishingDocument(0) + : UBAbstractPublisher(parent) + , mSourceDocument(pDocument) + , mPublishingDocument(0) + , mUsername(0) + , mPassword(0) { - connect(this, SIGNAL(authenticated(const QUuid&, const QString&)) - , this, SLOT(postDocument(const QUuid&, const QString&))); + mpWebView = new QWebView(0); + UBApplication::mainWindow->addSankoreWebDocumentWidget(mpWebView); + mpWebView->setWindowTitle(tr("Sankore Uploading Page")); + mpWebView->setAcceptDrops(false); + + connect(mpWebView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); + connect(mpWebView, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl))); + + + init(); } UBDocumentPublisher::~UBDocumentPublisher() { + delete mpWebView; delete mPublishingDocument; } void UBDocumentPublisher::publish() { - UBAbstractPublisher::authenticate(); + //check that the username and password are stored on preferences + mUsername = "Admin"; + mPassword = "admin"; + buildUbwFile(); + UBApplication::showMessage(tr("Uploading Sankore File on Web.")); + sendUbw(); + } -void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& encryptedBase64Token) +void UBDocumentPublisher::buildUbwFile() { - mAuthenticationUuid = tokenUuid; - mAuthenticationBase64Token = encryptedBase64Token; - - UBDocumentPublishingDialog dialog(UBApplication::mainWindow); + QDir d; + d.mkpath(UBFileSystemUtils::defaultTempDirPath()); - dialog.videoWarning->setVisible(UBPersistenceManager::persistenceManager()->mayHaveVideo(mSourceDocument)); + QString tmpDir = UBFileSystemUtils::createTempDir(); - dialog.title->setText(mSourceDocument->name()); - - QString defaultEMail = UBSettings::settings()->uniboardWebEMail->get().toString(); - dialog.email->setText(defaultEMail); - - QString defaultAuthor = UBSettings::settings()->uniboardWebAuthor->get().toString(); - dialog.author->setText(defaultAuthor); - - if (dialog.exec() == QDialog::Accepted) + if (UBFileSystemUtils::copyDir(mSourceDocument->persistencePath(), tmpDir)) { - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - UBApplication::showMessage(tr("Preparing document for upload..."), true); - - mTitle = dialog.title->text(); - mDescription = dialog.description->toPlainText(); - mEMail = dialog.email->text(); - mAuthor = dialog.author->text(); + QUuid publishingUuid = QUuid::createUuid(); - bool attachPDF = dialog.attachPDF->isChecked(); - bool attachUBZ = dialog.attachUBZ->isChecked(); + mPublishingDocument = new UBDocumentProxy(tmpDir); + mPublishingDocument->setPageCount(mSourceDocument->pageCount()); - mPublishingServiceUrl = UBSettings::settings()->documentsPublishingUrl; + rasterizeScenes(); - UBSettings::settings()->uniboardWebEMail->set(mEMail); - UBSettings::settings()->uniboardWebAuthor->set(mAuthor); + upgradeDocumentForPublishing(); - QDir d; - d.mkpath(UBFileSystemUtils::defaultTempDirPath()); + UBExportFullPDF pdfExporter; + pdfExporter.setVerbode(false); + pdfExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf"); - QString tmpDir = UBFileSystemUtils::createTempDir(); + UBExportDocument ubzExporter; + ubzExporter.setVerbode(false); + ubzExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz"); - if (UBFileSystemUtils::copyDir(mSourceDocument->persistencePath(), tmpDir)) - { - QUuid publishingUuid = QUuid::createUuid(); - - mPublishingDocument = new UBDocumentProxy(tmpDir); - mPublishingDocument->setPageCount(mSourceDocument->pageCount()); - - rasterizeScenes(); - //rasterizePDF(); // not needed as we do not publish svg file anymore + // remove all useless files - //rasterizeSVGImages(); // not needed as we do not publish svg file anymore + for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) { + QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); - upgradeDocumentForPublishing(); - - if (attachPDF) - { - UBExportFullPDF pdfExporter; - pdfExporter.setVerbode(false); - pdfExporter.persistsDocument(mSourceDocument, - mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf"); - } - - if (attachUBZ) - { - UBExportDocument ubzExporter; - ubzExporter.setVerbode(false); - ubzExporter.persistsDocument(mSourceDocument, - mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz"); - } - - // remove all useless files - - for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) - { - QString filename = mPublishingDocument->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); - - QFile::remove(filename); - } - - UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::imageDirectory); - UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::objectDirectory); - UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory); - UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory); + QFile::remove(filename); + } - QString tempZipFile = UBFileSystemUtils::defaultTempDirPath() - + "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip"; + UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::imageDirectory); + UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::objectDirectory); + UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory); + UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory); - //qDebug() << "compressing" << mPublishingDocument->persistencePath() << "in" << tempZipFile; + mTmpZipFile = UBFileSystemUtils::defaultTempDirPath() + "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip"; - QuaZip zip(tempZipFile); - zip.setFileNameCodec("UTF-8"); - if (!zip.open(QuaZip::mdCreate)) - { - qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << tempZipFile; - QApplication::restoreOverrideCursor(); - return; - } - - QuaZipFile outFile(&zip); + QuaZip zip(mTmpZipFile); + zip.setFileNameCodec("UTF-8"); + if (!zip.open(QuaZip::mdCreate)) + { + qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << mTmpZipFile; + QApplication::restoreOverrideCursor(); + return; + } - if (!UBFileSystemUtils::compressDirInZip(mPublishingDocument->persistencePath(), "", &outFile, true)) - { - qWarning("Export failed. compressDirInZip failed ..."); - zip.close(); - //zip.remove(); - UBApplication::showMessage(tr("Export failed.")); - QApplication::restoreOverrideCursor(); - return; - } - - if (zip.getZipError() != 0) - { - qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); - zip.close(); - //zip.remove(); - UBApplication::showMessage(tr("Export failed.")); - QApplication::restoreOverrideCursor(); - return; - } + QuaZipFile outFile(&zip); + if (!UBFileSystemUtils::compressDirInZip(mPublishingDocument->persistencePath(), "", &outFile, true)) + { + qWarning("Export failed. compressDirInZip failed ..."); zip.close(); - - mPublishingUrl = QUrl(mPublishingServiceUrl + "/documents/publish/" - + UBStringUtils::toCanonicalUuid(mSourceDocument->uuid())); - - sendZipToUniboardWeb(tempZipFile, publishingUuid); + UBApplication::showMessage(tr("Export failed.")); + QApplication::restoreOverrideCursor(); + return; } - else + + if (zip.getZipError() != 0) { - UBApplication::showMessage(tr("Export failed ...")); + qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); + zip.close(); + UBApplication::showMessage(tr("Export failed.")); QApplication::restoreOverrideCursor(); + return; } + + zip.close(); + } else { @@ -192,64 +150,16 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en } } - -/* - * // not needed as we do not publish svg file anymore - * - -void UBDocumentPublisher::rasterizePDF() -{ - if (UBPersistenceManager::persistenceManager()->mayHavePDF(mPublishingDocument)) - { - UBSvgSubsetAdaptor::convertPDFObjectsToImages(mPublishingDocument); - - QDir objectDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::objectDirectory); - - QStringList filters; - filters << "*.pdf"; - - foreach(QFileInfo fi, objectDir.entryInfoList(filters)) - { - QFile::remove(fi.absoluteFilePath()); - } - } -} -*/ - -/* - * // not needed as we do not publish svg file anymore - - -void UBDocumentPublisher::rasterizeSVGImages() -{ - if (UBPersistenceManager::persistenceManager()->mayHaveSVGImages(mPublishingDocument)) - { - UBSvgSubsetAdaptor::convertSvgImagesToImages(mPublishingDocument); - - QDir objectDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::imageDirectory); - - QStringList filters; - filters << "*.svg"; - - foreach(QFileInfo fi, objectDir.entryInfoList(filters)) - { - QFile::remove(fi.absoluteFilePath()); - } - } -} -*/ - void UBDocumentPublisher::rasterizeScenes() { - for(int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) + for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) { UBApplication::showMessage(tr("Converting page %1/%2 ...").arg(pageIndex + 1).arg(mPublishingDocument->pageCount()), true); UBSvgSubsetRasterizer rasterizer(mPublishingDocument, pageIndex); - QString filename = mPublishingDocument->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.jpg", pageIndex + 1); + QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.jpg", pageIndex + 1); rasterizer.rasterizeToFile(filename); @@ -275,7 +185,7 @@ void UBDocumentPublisher::updateGoogleMapApiKey() { QFile file(fileInfo.absoluteFilePath()); - if(file.open(QIODevice::ReadWrite)) + if (file.open(QIODevice::ReadWrite)) { QTextStream stream(&file); QString content = stream.readAll(); @@ -298,7 +208,7 @@ void UBDocumentPublisher::updateGoogleMapApiKey() void UBDocumentPublisher::upgradeDocumentForPublishing() { - for(int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) + for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) { UBGraphicsScene *scene = UBSvgSubsetAdaptor::loadScene(mPublishingDocument, pageIndex); @@ -306,25 +216,17 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() QList widgets; - foreach(QGraphicsItem* item, scene->items()) - { + foreach(QGraphicsItem* item, scene->items()){ UBGraphicsW3CWidgetItem *widgetItem = dynamic_cast(item); - if (widgetItem) - { + if(widgetItem){ generateWidgetPropertyScript(widgetItem, pageIndex + 1); sceneHasWidget = true; widgets << widgetItem; } } - //if (sceneHasWidget) - //{ - // updateSVGForWidget(pageIndex); // not needed as we do not publish svg file anymore - //} - - QString filename = mPublishingDocument->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.json", pageIndex + 1); + QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.json", pageIndex + 1); QFile jsonFile(filename); if (jsonFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) @@ -381,10 +283,10 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() sep = ""; jsonFile.write(QString(" \"%1\": \"%2\"%3\n") - .arg(key) - .arg(preferences.value(key)) - .arg(sep) - .toUtf8()); + .arg(key) + .arg(preferences.value(key)) + .arg(sep) + .toUtf8()); } jsonFile.write(QString(" },\n").toUtf8()); @@ -399,10 +301,10 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() sep = ""; jsonFile.write(QString(" \"%1\": \"%2\"%3\n") - .arg(entry) - .arg(datastoreEntries.value(entry)) - .arg(sep) - .toUtf8()); + .arg(entry) + .arg(datastoreEntries.value(entry)) + .arg(sep) + .toUtf8()); } jsonFile.write(QString(" }\n").toUtf8()); @@ -426,57 +328,6 @@ void UBDocumentPublisher::upgradeDocumentForPublishing() } -/** // not needed as we do not publish svg file anymore -void UBDocumentPublisher::updateSVGForWidget(int pageIndex) -{ - QString fileName = mPublishingDocument->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); - - QFile svgFile(fileName); - - if (svgFile.exists()) - { - if (!svgFile.open(QIODevice::ReadWrite)) - { - qWarning() << "Cannot open file " << fileName << " for widget upgrade ..."; - return; - } - - QTextStream stream(&svgFile); - QStringList lines; - - QString line; - do - { - line = stream.readLine(); - if (!line.isNull()) - { - if (line.contains("")) // TODO UB 4.6, this is naive ... the SVG tag may be on several lines - { - lines << "documentPlayerCssUrl + "\" ?>"; - lines << line; - lines << ""; - lines << "