Merge branch 'master' of github.com:Sankore/Sankore-3.1

preferencesAboutTextFull
shibakaneki 14 years ago
commit b650a8af79
  1. 49
      release.linux.sh
  2. 69
      resources/images/hflipTool.svg
  3. 68
      resources/images/vflipTool.svg
  4. 4
      resources/linux/run.sh
  5. 2
      resources/sankore.qrc
  6. 2
      src/adaptors/UBExportDocument.cpp
  7. 8
      src/adaptors/UBImportVirtualPrinter.cpp
  8. 2
      src/adaptors/UBMetadataDcSubsetAdaptor.cpp
  9. 37
      src/adaptors/UBSvgSubsetAdaptor.cpp
  10. 3
      src/adaptors/UBSvgSubsetAdaptor.h
  11. 2
      src/adaptors/UBWebPublisher.cpp
  12. 522
      src/adaptors/publishing/UBDocumentPublisher.cpp
  13. 83
      src/adaptors/publishing/UBDocumentPublisher.h
  14. 2
      src/board/UBBoardController.cpp
  15. 4
      src/board/UBBoardPaletteManager.cpp
  16. 3
      src/board/UBDrawingController.cpp
  17. 2
      src/board/UBDrawingController.h
  18. 2
      src/board/UBLibraryController.cpp
  19. 20
      src/core/UBApplication.cpp
  20. 1
      src/core/UBApplication.h
  21. 34
      src/core/UBApplicationController.cpp
  22. 7
      src/core/UBApplicationController.h
  23. 4
      src/core/UBDisplayManager.cpp
  24. 6
      src/core/UBDocumentManager.cpp
  25. 2
      src/core/UBPersistenceManager.cpp
  26. 2
      src/core/UBSceneCache.h
  27. 5
      src/core/main.cpp
  28. 2
      src/desktop/UBDesktopAnnotationController.cpp
  29. 2
      src/document/UBDocumentController.cpp
  30. 6
      src/document/UBDocumentController.h
  31. 10
      src/domain/UBGraphicsScene.cpp
  32. 1
      src/domain/UBGraphicsScene.h
  33. 1
      src/frameworks/UBCoreGraphicsScene.cpp
  34. 5
      src/frameworks/UBPlatformUtils_linux.cpp
  35. 6
      src/frameworks/UBPlatformUtils_mac.mm
  36. 2
      src/gui/UBDockPalette.cpp
  37. 8
      src/gui/UBFloatingPalette.cpp
  38. 6
      src/gui/UBFloatingPalette.h
  39. 490
      src/gui/UBKeyboardPalette.cpp
  40. 2
      src/gui/UBKeyboardPalette_linux.cpp
  41. 12
      src/gui/UBLibNavigatorWidget.cpp
  42. 14
      src/gui/UBMainWindow.cpp
  43. 5
      src/gui/UBMainWindow.h
  44. 1
      src/network/UBNetworkAccessManager.cpp
  45. 13
      src/pdf/XPDFRenderer.cpp
  46. 2
      src/podcast/UBPodcastController.cpp
  47. 103
      src/tools/UBAbstractDrawRuler.cpp
  48. 62
      src/tools/UBAbstractDrawRuler.h
  49. 334
      src/tools/UBGraphicsProtractor.cpp
  50. 45
      src/tools/UBGraphicsProtractor.h
  51. 430
      src/tools/UBGraphicsRuler.cpp
  52. 84
      src/tools/UBGraphicsRuler.h
  53. 547
      src/tools/UBGraphicsTriangle.cpp
  54. 92
      src/tools/UBGraphicsTriangle.h
  55. 2
      src/web/browser/WBWebView.cpp

@ -2,8 +2,23 @@
make clean make clean
rm -rf build/linux/release/ rm -rf build/linux/release/
rm -rf install
/usr/bin/qmake-qt4 QT_PATH="/usr/local/Trolltech/Qt-4.7.0"
PLUGINS_PATH="$QT_PATH/plugins"
QMAKE_PATH="$QT_PATH/bin/qmake"
if [ ! -e "$QMAKE_PATH" ]; then
echo "qmake command not found at $QMAKE_PATH"
exit 1
fi
if [ ! -e "$PLUGINS_PATH" ]; then
echo "plugins path not found at $PLUGINS_PATH"
exit 1
fi
$QMAKE_PATH -spec linux-g++
make -j 4 release-install make -j 4 release-install
@ -25,7 +40,36 @@ chmod +x build/linux/release/product/run.sh
cp -R resources/linux/qtlinux/* build/linux/release/product/ cp -R resources/linux/qtlinux/* build/linux/release/product/
cp -R /usr/lib/qt4/plugins build/linux/release/product/ #copying plugins
cp -R $PLUGINS_PATH build/linux/release/product/
#removing debug version
find build/linux/release/product/ -name *.debug -exec rm {} \;
#copying custom qt library
QT_LIBRARY_DEST_PATH="build/linux/release/product/qtlib"
mkdir $QT_LIBRARY_DEST_PATH
QT_LIBRARY_SOURCE_PATH="$QT_PATH/lib"
copyQtLibrary(){
if [ ! -e "$QT_LIBRARY_SOURCE_PATH/$1.so.4" ]; then
echo "library not found: $QT_LIBRARY_SOURCE_PATH"
exit 1;
fi
cp "$QT_LIBRARY_SOURCE_PATH/$1.so.4" "$QT_LIBRARY_DEST_PATH/"
cp "$QT_LIBRARY_SOURCE_PATH/$1.so.4.7.0" "$QT_LIBRARY_DEST_PATH/"
}
copyQtLibrary libQtWebKit
copyQtLibrary libphonon
copyQtLibrary libQtDBus
copyQtLibrary libQtScript
copyQtLibrary libQtSvg
copyQtLibrary libQtXmlPatterns
copyQtLibrary libQtNetwork
copyQtLibrary libQtXml
copyQtLibrary libQtGui
copyQtLibrary libQtCore
rm -rf install/linux rm -rf install/linux
mkdir -p install/linux mkdir -p install/linux
@ -36,3 +80,4 @@ cd build/linux/release
# "Removing .svn directories ..." # "Removing .svn directories ..."
find . -name .svn -exec rm -rf {} \; 2> /dev/null find . -name .svn -exec rm -rf {} \; 2> /dev/null
tar cvzf ../../../install/linux/Sankore\ 3.1.tar.gz Sankore_3.1.$VERSION -C . tar cvzf ../../../install/linux/Sankore\ 3.1.tar.gz Sankore_3.1.$VERSION -C .
echo "Build Finished"; alert

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Layer_1"
x="0px"
y="0px"
width="26.703px"
height="22.297px"
viewBox="0 0 26.703 22.297"
enable-background="new 0 0 26.703 22.297"
xml:space="preserve"
inkscape:version="0.48.1 "
sodipodi:docname="closeTool.svg"><metadata
id="metadata3009"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs3007" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1016"
inkscape:window-height="660"
id="namedview3005"
showgrid="false"
inkscape:snap-bbox="false"
inkscape:zoom="11.70561"
inkscape:cx="13.3515"
inkscape:cy="11.1485"
inkscape:window-x="289"
inkscape:window-y="195"
inkscape:window-maximized="0"
inkscape:current-layer="g2999" />
<g
id="g2999"
transform="translate(0.08542912,0)">
<path
clip-rule="evenodd"
stroke-miterlimit="3.8637"
d="m 17.978,0.507 c 4.546179,-0.0864046 8.231,3.686 8.231,8.232 l 0,4.838 c 0,4.547 -3.685,8.232 -8.231,8.232 l -9.246,0 c -4.546,0 -8.231,-3.686 -8.231,-8.232 l 0,-4.838 c 0,-4.547 3.943108,-7.97477519 8.4872874,-8.06114175 z"
id="path3001"
inkscape:connector-curvature="0"
style="fill:#333333;fill-rule:evenodd;stroke:#cdcccc;stroke-miterlimit:3.86369991"
sodipodi:nodetypes="sssssssss" />
<path
style="fill:none;stroke:#f9f9f9;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 14.950096,5.2111765 0.170859,12.4726515 5.894609,-2.562873 z"
id="path3015"
inkscape:connector-curvature="0"
transform="translate(-0.08542912,-8.119964e-7)" /><path
style="fill:#cccccc;stroke:#f9f9f9;stroke-width:1.04033172000000000px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 12.50192,5.211176 12.317001,17.683828 5.9373238,15.120955 z"
id="path3015-5"
inkscape:connector-curvature="0" /></g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Layer_1"
x="0px"
y="0px"
width="26.703px"
height="22.297px"
viewBox="0 0 26.703 22.297"
enable-background="new 0 0 26.703 22.297"
xml:space="preserve"
inkscape:version="0.48.1 "
sodipodi:docname="hrotateTool.svg"><metadata
id="metadata3009"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs3007" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1016"
inkscape:window-height="660"
id="namedview3005"
showgrid="false"
inkscape:snap-bbox="false"
inkscape:zoom="11.70561"
inkscape:cx="13.3515"
inkscape:cy="11.1485"
inkscape:window-x="289"
inkscape:window-y="195"
inkscape:window-maximized="0"
inkscape:current-layer="g2999" />
<g
id="g2999"
transform="translate(0.08542912,0)">
<path
clip-rule="evenodd"
stroke-miterlimit="3.8637"
d="m 17.892571,0.59242912 c 4.546179,-0.0864046 8.231,3.68599998 8.231,8.23199998 l 0,4.8379999 c 0,4.547 -3.685,8.232 -8.231,8.232 l -9.2460001,0 c -4.546,0 -8.23100002,-3.686 -8.23100002,-8.232 l 0,-4.8379999 c 0,-4.547 3.94310802,-7.97477517 8.48728742,-8.06114173 z"
id="path3001"
inkscape:connector-curvature="0"
style="fill:#333333;fill-rule:evenodd;stroke:#cdcccc;stroke-miterlimit:3.86369991"
sodipodi:nodetypes="sssssssss" />
<path
style="fill:none;stroke:#f9f9f9;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 6.4498984,10.208779 18.922551,10.03792 16.359678,4.1433112 z"
id="path3015"
inkscape:connector-curvature="0" /><path
style="fill:#cccccc;stroke:#f9f9f9;stroke-width:1.04033172px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 6.4004609,12.094944 18.873113,12.279863 16.31024,18.65954 z"
id="path3015-5"
inkscape:connector-curvature="0" /></g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

@ -1,4 +1,2 @@
#!/bin/sh #!/bin/sh
LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH env LD_LIBRARY_PATH=$PWD/qtlib:$LD_LIBRARY_PATH ./Sankore\ 3.1
export LD_LIBRARY_PATH
./Sankore\ 3.1

@ -33,6 +33,8 @@
<file>images/resizeRuler.svg</file> <file>images/resizeRuler.svg</file>
<file>images/resizeCompass.svg</file> <file>images/resizeCompass.svg</file>
<file>images/closeTool.svg</file> <file>images/closeTool.svg</file>
<file>images/hflipTool.svg</file>
<file>images/vflipTool.svg</file>
<file>images/resetTool.svg</file> <file>images/resetTool.svg</file>
<file>images/angleMarker.svg</file> <file>images/angleMarker.svg</file>
<file>images/currentDocument.png</file> <file>images/currentDocument.png</file>

@ -99,5 +99,5 @@ QString UBExportDocument::exportExtention()
QString UBExportDocument::exportName() QString UBExportDocument::exportName()
{ {
return tr("Export to Uniboard Format"); return tr("Export to Sankore Format");
} }

@ -132,7 +132,7 @@ void UBImportVirtualPrinter::cleanUp(const QFile& pFile, const QString& pPdfFile
UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QString& pGroup) 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; UBDocumentProxy *document = 0;
QString pdfFilename = pdfFileName(pFile); QString pdfFilename = pdfFileName(pFile);
@ -159,7 +159,7 @@ UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QS
if (!document) 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)); 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) 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; bool result = false;
QString pdfFilename = pdfFileName(pFile); QString pdfFilename = pdfFileName(pFile);
@ -183,7 +183,7 @@ bool UBImportVirtualPrinter::addFileToDocument(UBDocumentProxy* pDocument, const
if (!result) 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)); cleanUp(pFile, pdfFilename, emfFileNames(pFile));

@ -204,7 +204,7 @@ QMap<QString, QVariant> UBMetadataDcSubsetAdaptor::load(QString pPath)
if (xml.hasError()) if (xml.hasError())
{ {
qWarning() << "error parsing uniboard metadata.rdf file " << xml.errorString(); qWarning() << "error parsing sankore metadata.rdf file " << xml.errorString();
} }
} }

@ -26,6 +26,7 @@
#include "tools/UBGraphicsCompass.h" #include "tools/UBGraphicsCompass.h"
#include "tools/UBGraphicsProtractor.h" #include "tools/UBGraphicsProtractor.h"
#include "tools/UBGraphicsCurtainItem.h" #include "tools/UBGraphicsCurtainItem.h"
#include "tools/UBGraphicsTriangle.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
@ -644,6 +645,16 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(protractor); scene->addItem(protractor);
scene->registerTool(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") else if (mXmlReader.name() == "foreignObject")
{ {
@ -770,7 +781,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
if (mXmlReader.hasError()) if (mXmlReader.hasError())
{ {
qWarning() << "error parsing uniboard file " << mXmlReader.errorString(); qWarning() << "error parsing Sankore file " << mXmlReader.errorString();
} }
if (scene) if (scene)
@ -2556,7 +2567,31 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg()
return protractor; 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 svgX = mXmlReader.attributes().value("x");
QStringRef svgY = mXmlReader.attributes().value("y");
QStringRef svgWidth = mXmlReader.attributes().value("width");
QStringRef svgHeight = mXmlReader.attributes().value("height");
QStringRef orientationStringRef = mXmlReader.attributes().value("orientation");
UBGraphicsTriangle::UBGraphicsTriangleOrientation orientation = UBGraphicsTriangle::orientationFromStr(orientationStringRef);
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) void UBSvgSubsetAdaptor::convertPDFObjectsToImages(UBDocumentProxy* proxy)
{ {

@ -31,6 +31,7 @@ class UBGraphicsScene;
class UBDocumentProxy; class UBDocumentProxy;
class UBGraphicsStroke; class UBGraphicsStroke;
class UBPersistenceManager; class UBPersistenceManager;
class UBGraphicsTriangle;
class UBSvgSubsetAdaptor class UBSvgSubsetAdaptor
{ {
@ -118,6 +119,8 @@ class UBSvgSubsetAdaptor
UBGraphicsProtractor* protractorFromSvg(); UBGraphicsProtractor* protractorFromSvg();
UBGraphicsTriangle* triangleFromSvg();
void graphicsItemFromSvg(QGraphicsItem* gItem); void graphicsItemFromSvg(QGraphicsItem* gItem);
QXmlStreamReader mXmlReader; QXmlStreamReader mXmlReader;

@ -28,7 +28,7 @@ UBWebPublisher::~UBWebPublisher()
QString UBWebPublisher::exportName() QString UBWebPublisher::exportName()
{ {
return tr("Publish Document on Uniboard Web"); return tr("Publish Document on Sankore Web");
} }

@ -1,4 +1,4 @@
#include "UBDocumentPublisher.h" #include "UBDocumentPublisher.h"
#include "frameworks/UBPlatformUtils.h" #include "frameworks/UBPlatformUtils.h"
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
@ -10,6 +10,7 @@
#include "core/UBDocumentManager.h" #include "core/UBDocumentManager.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "core/UBApplicationController.h"
#include "gui/UBMainWindow.h" #include "gui/UBMainWindow.h"
@ -28,162 +29,119 @@
#include "core/memcheck.h" #include "core/memcheck.h"
UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent) UBDocumentPublisher::UBDocumentPublisher(UBDocumentProxy* pDocument, QObject *parent)
: UBAbstractPublisher(parent) : UBAbstractPublisher(parent)
, mSourceDocument(pDocument) , mSourceDocument(pDocument)
, mPublishingDocument(0) , mPublishingDocument(0)
, mUsername("")
, mPassword("")
{ {
connect(this, SIGNAL(authenticated(const QUuid&, const QString&)) mpWebView = new QWebView(0);
, this, SLOT(postDocument(const QUuid&, const QString&))); 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() UBDocumentPublisher::~UBDocumentPublisher()
{ {
delete mpWebView;
delete mPublishingDocument; delete mPublishingDocument;
} }
void UBDocumentPublisher::publish() 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; QDir d;
mAuthenticationBase64Token = encryptedBase64Token; d.mkpath(UBFileSystemUtils::defaultTempDirPath());
UBDocumentPublishingDialog dialog(UBApplication::mainWindow);
dialog.videoWarning->setVisible(UBPersistenceManager::persistenceManager()->mayHaveVideo(mSourceDocument));
dialog.title->setText(mSourceDocument->name());
QString defaultEMail = UBSettings::settings()->uniboardWebEMail->get().toString();
dialog.email->setText(defaultEMail);
QString defaultAuthor = UBSettings::settings()->uniboardWebAuthor->get().toString(); QString tmpDir = UBFileSystemUtils::createTempDir();
dialog.author->setText(defaultAuthor);
if (dialog.exec() == QDialog::Accepted) if (UBFileSystemUtils::copyDir(mSourceDocument->persistencePath(), tmpDir))
{ {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QUuid publishingUuid = QUuid::createUuid();
UBApplication::showMessage(tr("Preparing document for upload..."), true);
mTitle = dialog.title->text(); mPublishingDocument = new UBDocumentProxy(tmpDir);
mDescription = dialog.description->toPlainText(); mPublishingDocument->setPageCount(mSourceDocument->pageCount());
mEMail = dialog.email->text();
mAuthor = dialog.author->text();
bool attachPDF = dialog.attachPDF->isChecked(); rasterizeScenes();
bool attachUBZ = dialog.attachUBZ->isChecked();
mPublishingServiceUrl = UBSettings::settings()->documentsPublishingUrl; upgradeDocumentForPublishing();
UBSettings::settings()->uniboardWebEMail->set(mEMail); UBExportFullPDF pdfExporter;
UBSettings::settings()->uniboardWebAuthor->set(mAuthor); pdfExporter.setVerbode(false);
pdfExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf");
QDir d; UBExportDocument ubzExporter;
d.mkpath(UBFileSystemUtils::defaultTempDirPath()); ubzExporter.setVerbode(false);
ubzExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz");
QString tmpDir = UBFileSystemUtils::createTempDir();
if (UBFileSystemUtils::copyDir(mSourceDocument->persistencePath(), tmpDir)) // remove all useless files
{
QUuid publishingUuid = QUuid::createUuid();
mPublishingDocument = new UBDocumentProxy(tmpDir);
mPublishingDocument->setPageCount(mSourceDocument->pageCount());
rasterizeScenes();
//rasterizePDF(); // not needed as we do not publish svg file anymore
//rasterizeSVGImages(); // not needed as we do not publish svg file anymore
upgradeDocumentForPublishing(); for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) {
QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1);
if (attachPDF) QFile::remove(filename);
{ }
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);
QString tempZipFile = UBFileSystemUtils::defaultTempDirPath()
+ "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip";
//qDebug() << "compressing" << mPublishingDocument->persistencePath() << "in" << tempZipFile;
QuaZip zip(tempZipFile); UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::imageDirectory);
zip.setFileNameCodec("UTF-8"); UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::objectDirectory);
if (!zip.open(QuaZip::mdCreate)) UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory);
{ UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory);
qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << tempZipFile;
QApplication::restoreOverrideCursor();
return;
}
QuaZipFile outFile(&zip); mTmpZipFile = UBFileSystemUtils::defaultTempDirPath() + "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip";
if (!UBFileSystemUtils::compressDirInZip(mPublishingDocument->persistencePath(), "", &outFile, true)) QuaZip zip(mTmpZipFile);
{ zip.setFileNameCodec("UTF-8");
qWarning("Export failed. compressDirInZip failed ..."); if (!zip.open(QuaZip::mdCreate))
zip.close(); {
//zip.remove(); qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << mTmpZipFile;
UBApplication::showMessage(tr("Export failed.")); QApplication::restoreOverrideCursor();
QApplication::restoreOverrideCursor(); return;
return; }
}
if (zip.getZipError() != 0) QuaZipFile outFile(&zip);
{
qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError());
zip.close();
//zip.remove();
UBApplication::showMessage(tr("Export failed."));
QApplication::restoreOverrideCursor();
return;
}
if (!UBFileSystemUtils::compressDirInZip(mPublishingDocument->persistencePath(), "", &outFile, true))
{
qWarning("Export failed. compressDirInZip failed ...");
zip.close(); zip.close();
UBApplication::showMessage(tr("Export failed."));
mPublishingUrl = QUrl(mPublishingServiceUrl + "/documents/publish/" QApplication::restoreOverrideCursor();
+ UBStringUtils::toCanonicalUuid(mSourceDocument->uuid())); return;
sendZipToUniboardWeb(tempZipFile, publishingUuid);
} }
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(); QApplication::restoreOverrideCursor();
return;
} }
zip.close();
} }
else 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() 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); UBApplication::showMessage(tr("Converting page %1/%2 ...").arg(pageIndex + 1).arg(mPublishingDocument->pageCount()), true);
UBSvgSubsetRasterizer rasterizer(mPublishingDocument, pageIndex); UBSvgSubsetRasterizer rasterizer(mPublishingDocument, pageIndex);
QString filename = mPublishingDocument->persistencePath() + QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.jpg", pageIndex + 1);
UBFileSystemUtils::digitFileFormat("/page%1.jpg", pageIndex + 1);
rasterizer.rasterizeToFile(filename); rasterizer.rasterizeToFile(filename);
@ -275,7 +185,7 @@ void UBDocumentPublisher::updateGoogleMapApiKey()
{ {
QFile file(fileInfo.absoluteFilePath()); QFile file(fileInfo.absoluteFilePath());
if(file.open(QIODevice::ReadWrite)) if (file.open(QIODevice::ReadWrite))
{ {
QTextStream stream(&file); QTextStream stream(&file);
QString content = stream.readAll(); QString content = stream.readAll();
@ -298,7 +208,7 @@ void UBDocumentPublisher::updateGoogleMapApiKey()
void UBDocumentPublisher::upgradeDocumentForPublishing() 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); UBGraphicsScene *scene = UBSvgSubsetAdaptor::loadScene(mPublishingDocument, pageIndex);
@ -306,25 +216,17 @@ void UBDocumentPublisher::upgradeDocumentForPublishing()
QList<UBGraphicsW3CWidgetItem*> widgets; QList<UBGraphicsW3CWidgetItem*> widgets;
foreach(QGraphicsItem* item, scene->items()) foreach(QGraphicsItem* item, scene->items()){
{
UBGraphicsW3CWidgetItem *widgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(item); UBGraphicsW3CWidgetItem *widgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(item);
if (widgetItem) if(widgetItem){
{
generateWidgetPropertyScript(widgetItem, pageIndex + 1); generateWidgetPropertyScript(widgetItem, pageIndex + 1);
sceneHasWidget = true; sceneHasWidget = true;
widgets << widgetItem; widgets << widgetItem;
} }
} }
//if (sceneHasWidget) QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.json", pageIndex + 1);
//{
// updateSVGForWidget(pageIndex); // not needed as we do not publish svg file anymore
//}
QString filename = mPublishingDocument->persistencePath() +
UBFileSystemUtils::digitFileFormat("/page%1.json", pageIndex + 1);
QFile jsonFile(filename); QFile jsonFile(filename);
if (jsonFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) if (jsonFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
@ -381,10 +283,10 @@ void UBDocumentPublisher::upgradeDocumentForPublishing()
sep = ""; sep = "";
jsonFile.write(QString(" \"%1\": \"%2\"%3\n") jsonFile.write(QString(" \"%1\": \"%2\"%3\n")
.arg(key) .arg(key)
.arg(preferences.value(key)) .arg(preferences.value(key))
.arg(sep) .arg(sep)
.toUtf8()); .toUtf8());
} }
jsonFile.write(QString(" },\n").toUtf8()); jsonFile.write(QString(" },\n").toUtf8());
@ -399,10 +301,10 @@ void UBDocumentPublisher::upgradeDocumentForPublishing()
sep = ""; sep = "";
jsonFile.write(QString(" \"%1\": \"%2\"%3\n") jsonFile.write(QString(" \"%1\": \"%2\"%3\n")
.arg(entry) .arg(entry)
.arg(datastoreEntries.value(entry)) .arg(datastoreEntries.value(entry))
.arg(sep) .arg(sep)
.toUtf8()); .toUtf8());
} }
jsonFile.write(QString(" }\n").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("<svg") && line.contains(">")) // TODO UB 4.6, this is naive ... the SVG tag may be on several lines
{
lines << "<?xml-stylesheet type=\"text/css\" href=\"" + UBSettings::settings()->documentPlayerCssUrl + "\" ?>";
lines << line;
lines << "";
lines << " <script type=\"text/ecmascript\" xlink:href=\"" + UBSettings::settings()->documentPlayerScriptUrl + "\"/>";
lines << " <script type=\"text/ecmascript\" xlink:href=\"" + UBSettings::settings()->documentPlayerPageScriptUrl + "\"/>";
lines << "";
}
else
{
lines << line;
}
}
}
while (!line.isNull());
svgFile.resize(0);
svgFile.write(lines.join("\n").toUtf8()); // TODO UB 4.x detect real html encoding
svgFile.close();
}
}
*/
void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber) void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber)
{ {
@ -487,15 +338,13 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
if (!startFileName.startsWith("http://")) if (!startFileName.startsWith("http://"))
{ {
QString startFilePath = mPublishingDocument->persistencePath() + "/" QString startFilePath = mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + widgetItem->uuid().toString() + ".wgt/" + startFileName;
+ UBPersistenceManager::widgetDirectory + "/"
+ widgetItem->uuid().toString() + ".wgt/" + startFileName;
QFile startFile(startFilePath); QFile startFile(startFilePath);
if(startFile.exists()) if (startFile.exists())
{ {
if(startFile.open(QIODevice::ReadWrite)) if (startFile.open(QIODevice::ReadWrite))
{ {
QTextStream stream(&startFile); QTextStream stream(&startFile);
QStringList lines; QStringList lines;
@ -663,111 +512,138 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
} }
} }
} }
else else{
{
qWarning() << "Remote Widget start file, cannot inject widget preferences and datastore entries"; qWarning() << "Remote Widget start file, cannot inject widget preferences and datastore entries";
} }
} }
void UBDocumentPublisher::sendZipToUniboardWeb(const QString& zipFilePath, const QUuid& publishingUuid)
{
QFile zipFile(zipFilePath);
if(!zipFile.open(QIODevice::ReadOnly))
{
qWarning() << "Cannot open file" << zipFilePath << "for upload to Uniboard Web";
return;
}
QUrl publishingEndpoint = QUrl(mPublishingServiceUrl);
mUploadRequest = new UBServerXMLHttpRequest(UBNetworkAccessManager::defaultAccessManager() void UBDocumentPublisher::init()
, "application/octet-stream");
mUploadRequest->setVerbose(true);
connect(mUploadRequest, SIGNAL(progress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64)));
connect(mUploadRequest, SIGNAL(finished(bool, const QByteArray&)), this, SLOT(postZipUploadResponse(bool, const QByteArray&)));
mUploadRequest->addHeader("Publishing-UUID", UBStringUtils::toCanonicalUuid(publishingUuid));
mUploadRequest->addHeader("Document-UUID", UBStringUtils::toCanonicalUuid(mSourceDocument->uuid()));
mUploadRequest->addHeader("Document-PageCount", QString("%1").arg(mSourceDocument->pageCount()));
mUploadRequest->addHeader("Document-Title", mTitle);
mUploadRequest->addHeader("Document-Author", mAuthor);
mUploadRequest->addHeader("Document-AuthorEMail", mEMail);
mUploadRequest->addHeader("Document-Description", mDescription);
mUploadRequest->addHeader("Deletion-Token", UBStringUtils::toCanonicalUuid(QUuid::createUuid()));
mUploadRequest->addHeader("Token-UUID", UBStringUtils::toCanonicalUuid(mAuthenticationUuid));
mUploadRequest->addHeader("Token-Encrypted", mAuthenticationBase64Token);
mUploadRequest->post(publishingEndpoint, zipFile.readAll());
zipFile.remove();
}
void UBDocumentPublisher::uploadProgress(qint64 bytesSent, qint64 bytesTotal)
{ {
int percentage = (((qreal)bytesSent / (qreal)bytesTotal ) * 100); mCrlf=0x0d;
mCrlf+=0x0a;
if (bytesSent < bytesTotal) mpNetworkMgr = new QNetworkAccessManager(this);
UBApplication::showMessage(tr("Upload to Uniboard Web in progress %1 %").arg(percentage), true); mpCookieJar = new QNetworkCookieJar();
else
UBApplication::showMessage(tr("Sending document ..."), true);
connect(mpNetworkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
} }
void UBDocumentPublisher::onFinished(QNetworkReply *reply)
void UBDocumentPublisher::postZipUploadResponse(bool success, const QByteArray& payload)
{ {
if (success) QByteArray response = reply->readAll();
{
UBApplication::showMessage(tr("The document has been sent to %1").arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false); if (!bCookieSet)
}
else
{ {
qWarning() << "error uploading document to Uniboard Web" << QString::fromUtf8(payload); QList<QNetworkCookie> cookiesList;
QVariant cookieHeader = reply->rawHeader("Set-Cookie");
qDebug() << cookieHeader.toString();
// First we concatenate all the Set-Cookie values (the packet can contains many of them)
QStringList qslCookie = cookieHeader.toString().split("\n");
QString qsCookieValue = qslCookie.at(0);
for (int i = 1; i < qslCookie.size(); i++) {
qsCookieValue += "; " +qslCookie.at(i);
}
qDebug() << "qsCookieValue " << qsCookieValue;
// Now we isolate every cookie value
QStringList qslCookieVals = qsCookieValue.split("; ");
QString errorMessage = QString::fromUtf8(payload); // Finally we create the cookies
for (int i = 0; i < qslCookieVals.size(); i++)
{
QString cookieString = qslCookieVals.at(i);
qDebug() << "qslCookieVals.at(i): " << cookieString.replace("\"", "");
QStringList qslCrntCookie = cookieString.split("=");
QNetworkCookie crntCookie;
if (qslCrntCookie.length() == 2)
crntCookie = QNetworkCookie(qslCrntCookie.at(0).toAscii().constData(), qslCrntCookie.at(1).toAscii().constData());
else
crntCookie = QNetworkCookie(qslCrntCookie.at(0).toAscii().constData());
cookiesList << crntCookie;
}
if (errorMessage.length() == 0) // Set the cookiejar : it set the cookies that will be sent with every packet.
UBApplication::showMessage(tr("Error while publishing document to %1") qDebug() << reply->url().toString();
.arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false); mpCookieJar->setCookiesFromUrl(cookiesList, reply->url());
else mpNetworkMgr->setCookieJar(mpCookieJar);
UBApplication::showMessage(tr("Error while publishing document to %1 : (%2)") bCookieSet = true;
.arg(UBSettings::settings()->uniboardWebUrl->get().toString())
.arg(errorMessage), false);
} }
QApplication::restoreOverrideCursor(); if (response.isEmpty()){
emit loginDone();
}
else{
// Display the iframe
mpWebView->setHtml(response, QUrl("http://sankore.devxwiki.com/xwiki/bin/view/Test/FileUpload"));
UBApplication::applicationController->showSankoreWebDocument();
deleteLater(); }
} }
void UBDocumentPublisher::sendUbw()
UBDocumentPublishingDialog::UBDocumentPublishingDialog(QWidget *parent)
: QDialog(parent)
{ {
Ui::documentPublishingDialog::setupUi(this); if (QFile::exists(mTmpZipFile))
{
QFile f(mTmpZipFile);
if (f.open(QIODevice::ReadOnly))
{
QByteArray ba = f.readAll();
QString boundary,data, multipartHeader;
QByteArray datatoSend;
boundary = "---WebKitFormBoundaryDKBTgA53MiyWrzLY";
multipartHeader = "multipart/form-data; boundary="+boundary;
data="--"+boundary+mCrlf;
data+="Content-Disposition: form-data; name=\"file\"; filename=\""+ f.fileName() +"\""+mCrlf;
data+="Content-Type: application/octet-stream"+mCrlf+mCrlf;
datatoSend=data.toAscii(); // convert data string to byte array for request
datatoSend += ba;
datatoSend += mCrlf.toAscii();
datatoSend += QString("--%0--%1").arg(boundary).arg(mCrlf).toAscii();
QNetworkRequest request(QUrl("http://sankore.devxwiki.com/xwiki/bin/view/Test/FileUpload"));
request.setHeader(QNetworkRequest::ContentTypeHeader, multipartHeader);
request.setHeader(QNetworkRequest::ContentLengthHeader,datatoSend.size());
request.setRawHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
request.setRawHeader("Accept-Language", "en-US,*");
request.setRawHeader("Referer", "http://sankore.devxwiki.com/xwiki/bin/view/Test/FileUpload");
request.setRawHeader("Origin", "http://sankore.devxwiki.com");
QString b64Auth = getBase64Of(QString("%0:%1").arg(mUsername).arg(mPassword));
request.setRawHeader("Authorization", QString("Basic %0").arg(b64Auth).toAscii().constData());
// Send the file
mpNetworkMgr->post(request,datatoSend);
}
}
}
connect(dialogButtons, SIGNAL(accepted()), this, SLOT(accept())); QString UBDocumentPublisher::getBase64Of(QString stringToEncode)
connect(dialogButtons, SIGNAL(rejected()), this, SLOT(reject())); {
return stringToEncode.toAscii().toBase64();
}
connect(title, SIGNAL(textChanged(const QString&)), this, SLOT(updateUIState(const QString&))); void UBDocumentPublisher::onLinkClicked(const QUrl &url)
connect(email, SIGNAL(textChanged(const QString&)), this, SLOT(updateUIState(const QString&))); {
// [Basic Auth] Here we interpret the link and send the request with the basic auth header.
QNetworkRequest request;
request.setUrl(url);
QString b64Auth = getBase64Of(QString("%0:%1").arg(mUsername).arg(mPassword));
request.setRawHeader("Authorization", QString("Basic %0").arg(b64Auth).toAscii().constData());
mpNetworkMgr->get(request);
}
dialogButtons->button(QDialogButtonBox::Ok)->setEnabled(false); void UBDocumentPublisher::onLoadFinished(bool result)
dialogButtons->button(QDialogButtonBox::Ok)->setText(tr("Publish")); {
Q_UNUSED(result);
// [Basic Auth] This line says: if the user click on a link, do not interpret it.
mpWebView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
} }
void UBDocumentPublishingDialog::updateUIState(const QString& string)
{
Q_UNUSED(string);
bool ok = title->text().length() > 0
&& email->text().length() > 0;
dialogButtons->button(QDialogButtonBox::Ok)->setEnabled(ok);
}

@ -10,74 +10,55 @@
class UBDocumentProxy; class UBDocumentProxy;
class UBServerXMLHttpRequest; class UBServerXMLHttpRequest;
class UBGraphicsW3CWidgetItem; class UBGraphicsW3CWidgetItem;
class QWebView;
class UBDocumentPublisher : public UBAbstractPublisher class UBDocumentPublisher : public UBAbstractPublisher
{ {
Q_OBJECT; Q_OBJECT;
public: public:
explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0); explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0);
virtual ~UBDocumentPublisher(); virtual ~UBDocumentPublisher();
void publish(); void publish();
protected: signals:
// not needed as we do not publish svg file anymore void loginDone();
//virtual void rasterizePDF();
//virtual void rasterizeSVGImages();
//virtual void updateSVGForWidget(int sceneIndex);
virtual void updateGoogleMapApiKey(); protected:
virtual void rasterizeScenes(); virtual void updateGoogleMapApiKey();
virtual void rasterizeScenes();
virtual void upgradeDocumentForPublishing();
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber);
virtual void upgradeDocumentForPublishing(); private slots:
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber); void onFinished(QNetworkReply* reply);
void onLinkClicked(const QUrl& url);
void onLoadFinished(bool result);
void sendZipToUniboardWeb(const QString& zipFile, const QUuid& publishingUuid);
private slots: private:
void postDocument(const QUuid& tokenUuid, const QString& encryptedBase64Token); UBDocumentProxy *mSourceDocument;
void uploadProgress(qint64, qint64); UBDocumentProxy *mPublishingDocument;
void postZipUploadResponse(bool, const QByteArray&); void init();
void sendUbw();
QString getBase64Of(QString stringToEncode);
private: QWebView* mpWebView;
QHBoxLayout* mpLayout;
QNetworkAccessManager* mpNetworkMgr;
QNetworkCookieJar* mpCookieJar;
QString mUsername;
QString mPassword;
QString mCrlf;
bool bCookieSet;
UBDocumentProxy *mSourceDocument; void buildUbwFile();
UBDocumentProxy *mPublishingDocument; QString mTmpZipFile;
UBServerXMLHttpRequest* mUploadRequest;
QString mTitle;
QString mAuthor;
QString mDescription;
QString mEMail;
bool mAttachPDF;
bool mAttachUBZ;
QUrl mPublishingUrl;
QString mPublishingServiceUrl;
QUuid mAuthenticationUuid;
QString mAuthenticationBase64Token;
}; };
class UBDocumentPublishingDialog : public QDialog, public Ui::documentPublishingDialog
{
Q_OBJECT;
public:
UBDocumentPublishingDialog(QWidget *parent = 0);
~UBDocumentPublishingDialog(){}
private slots:
void updateUIState(const QString& string);
};
#endif // UBDOCUMENTPUBLISHER_H #endif // UBDOCUMENTPUBLISHER_H

@ -956,7 +956,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
} }
else 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")) else if (mimeType.startsWith("application/pdf"))

@ -152,7 +152,7 @@ void UBBoardPaletteManager::setupPalettes()
addItemActions << UBApplication::mainWindow->actionAddItemToCurrentPage; addItemActions << UBApplication::mainWindow->actionAddItemToCurrentPage;
addItemActions << UBApplication::mainWindow->actionAddItemToNewPage; addItemActions << UBApplication::mainWindow->actionAddItemToNewPage;
addItemActions << UBApplication::mainWindow->actionAddItemToLibrary; addItemActions << UBApplication::mainWindow->actionAddItemToLibrary;
//addItemActions << UBApplication::mainWindow->actionShareItemOnWeb; addItemActions << UBApplication::mainWindow->actionShareItemOnWeb;
mAddItemPalette = new UBActionPalette(addItemActions, Qt::Horizontal, 0); mAddItemPalette = new UBActionPalette(addItemActions, Qt::Horizontal, 0);
mAddItemPalette->setButtonIconSize(QSize(128, 128)); mAddItemPalette->setButtonIconSize(QSize(128, 128));
@ -306,7 +306,7 @@ void UBBoardPaletteManager::connectPalettes()
connect(UBApplication::mainWindow->actionAddItemToCurrentPage, SIGNAL(triggered()), this, SLOT(addItemToCurrentPage())); connect(UBApplication::mainWindow->actionAddItemToCurrentPage, SIGNAL(triggered()), this, SLOT(addItemToCurrentPage()));
connect(UBApplication::mainWindow->actionAddItemToNewPage, SIGNAL(triggered()), this, SLOT(addItemToNewPage())); connect(UBApplication::mainWindow->actionAddItemToNewPage, SIGNAL(triggered()), this, SLOT(addItemToNewPage()));
connect(UBApplication::mainWindow->actionAddItemToLibrary, SIGNAL(triggered()), this, SLOT(addItemToLibrary())); connect(UBApplication::mainWindow->actionAddItemToLibrary, SIGNAL(triggered()), this, SLOT(addItemToLibrary()));
//connect(UBApplication::mainWindow->actionShareItemOnWeb, SIGNAL(triggered()), this, SLOT(shareItemOnWeb())); connect(UBApplication::mainWindow->actionShareItemOnWeb, SIGNAL(triggered()), this, SLOT(shareItemOnWeb()));
connect(UBApplication::mainWindow->actionEraseItems, SIGNAL(triggered()), mErasePalette, SLOT(close())); connect(UBApplication::mainWindow->actionEraseItems, SIGNAL(triggered()), mErasePalette, SLOT(close()));
connect(UBApplication::mainWindow->actionEraseAnnotations, SIGNAL(triggered()), mErasePalette, SLOT(close())); connect(UBApplication::mainWindow->actionEraseAnnotations, SIGNAL(triggered()), mErasePalette, SLOT(close()));

@ -27,9 +27,10 @@ UBDrawingController* UBDrawingController::drawingController()
UBDrawingController::UBDrawingController(QObject * parent) UBDrawingController::UBDrawingController(QObject * parent)
: QObject(parent) : QObject(parent)
, mActiveRuler(NULL)
, mStylusTool((UBStylusTool::Enum)-1) , mStylusTool((UBStylusTool::Enum)-1)
, mLatestDrawingTool((UBStylusTool::Enum)-1) , mLatestDrawingTool((UBStylusTool::Enum)-1)
, mActiveRuler(NULL)
{ {
connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged())); connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged()));

@ -41,7 +41,7 @@ class UBDrawingController : public QObject
void setMarkerColor(bool onDarkBackground, const QColor& color, int pIndex); void setMarkerColor(bool onDarkBackground, const QColor& color, int pIndex);
void setMarkerAlpha(qreal alpha); void setMarkerAlpha(qreal alpha);
UBAbstractDrawRuler* mActiveRuler; UBAbstractDrawRuler* mActiveRuler;
public slots: public slots:

@ -724,7 +724,7 @@ UBLibElement* UBLibElement::trashElement()
if (trashElement) if (trashElement)
return 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"); QImage *categoryImage = new QImage(":images/libpalette/TrashCategory.svg");
trashElement->setThumbnail(categoryImage); trashElement->setThumbnail(categoryImage);
trashElement->setMoveable(false); trashElement->setMoveable(false);

@ -53,7 +53,6 @@ UBApplicationController* UBApplication::applicationController = 0;
UBBoardController* UBApplication::boardController = 0; UBBoardController* UBApplication::boardController = 0;
UBWebController* UBApplication::webController = 0; UBWebController* UBApplication::webController = 0;
UBDocumentController* UBApplication::documentController = 0; UBDocumentController* UBApplication::documentController = 0;
//UBSoftwareUpdateController* UBApplication::softwareUpdateController = 0;
UniboardSankoreTransition* UBApplication::mUniboardSankoreTransition = 0; UniboardSankoreTransition* UBApplication::mUniboardSankoreTransition = 0;
UBMainWindow* UBApplication::mainWindow = 0; UBMainWindow* UBApplication::mainWindow = 0;
@ -91,9 +90,8 @@ static OSStatus ub_appleEventProcessor(const AppleEvent *ae, AppleEvent *event,
#endif #endif
UBApplication::UBApplication(const QString &id, int &argc, char **argv) UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSingleApplication(id, argc, argv),
: QtSingleApplication(id, argc, argv), mPreferencesController(NULL)
mPreferencesController(NULL)
{ {
staticMemoryCleaner = new QObject(0); // deleted in UBApplication destructor staticMemoryCleaner = new QObject(0); // deleted in UBApplication destructor
@ -186,11 +184,11 @@ UBApplication::~UBApplication()
delete mUniboardSankoreTransition; delete mUniboardSankoreTransition;
mUniboardSankoreTransition = 0; mUniboardSankoreTransition = 0;
if (mPreferencesController) if (mPreferencesController)
{ {
delete mPreferencesController; delete mPreferencesController;
mPreferencesController = 0; mPreferencesController = 0;
} }
} }
int UBApplication::exec(const QString& pFileToImport) int UBApplication::exec(const QString& pFileToImport)
@ -343,6 +341,10 @@ void UBApplication::showDocument()
applicationController->showDocument(); applicationController->showDocument();
} }
void UBApplication::showSankoreWebDocument()
{
applicationController->showSankoreWebDocument();
}
int UBApplication::toolBarHeight() int UBApplication::toolBarHeight()
{ {

@ -88,6 +88,7 @@ class UBApplication : public QtSingleApplication
void showBoard(); void showBoard();
void showInternet(); void showInternet();
void showDocument(); void showDocument();
void showSankoreWebDocument();
void toolBarPositionChanged(QVariant topOrBottom); void toolBarPositionChanged(QVariant topOrBottom);
void toolBarDisplayTextChanged(QVariant display); void toolBarDisplayTextChanged(QVariant display);

@ -50,12 +50,13 @@ UBApplicationController::UBApplicationController(UBBoardView *pControlView, UBBo
, mControlView(pControlView) , mControlView(pControlView)
, mDisplayView(pDisplayView) , mDisplayView(pDisplayView)
, mMirror(0) , mMirror(0)
, mFtp(0)
, mMainMode(Board) , mMainMode(Board)
, mDisplayManager(0) , mDisplayManager(0)
, mAutomaticCheckForUpdates(false) , mAutomaticCheckForUpdates(false)
, mCheckingForUpdates(false) , mCheckingForUpdates(false)
, mIsShowingDesktop(false) , mIsShowingDesktop(false)
, mFtp(0)
{ {
mDisplayManager = new UBDisplayManager(this); mDisplayManager = new UBDisplayManager(this);
@ -87,11 +88,10 @@ UBApplicationController::UBApplicationController(UBBoardView *pControlView, UBBo
, this, SLOT(addCapturedPixmap(const QPixmap &, bool, const QUrl&))); , this, SLOT(addCapturedPixmap(const QPixmap &, bool, const QUrl&)));
networkAccessManager = new QNetworkAccessManager (this); networkAccessManager = new QNetworkAccessManager (this);
connect (networkAccessManager, SIGNAL (finished (QNetworkReply*)), this, SLOT (downloadJsonFinished (QNetworkReply*)));
QTimer::singleShot (1000, this, SLOT (checkUpdateAtLaunch())); QTimer::singleShot (1000, this, SLOT (checkUpdateAtLaunch()));
#ifdef Q_WS_X11 #ifdef Q_WS_X11
// mMainWindow->setStyleSheet("QToolButton { font-size: 11px}"); mMainWindow->setStyleSheet("QToolButton { font-size: 11px}");
#endif #endif
} }
@ -326,7 +326,7 @@ void UBApplicationController::showBoard()
if (UBApplication::boardController) if (UBApplication::boardController)
UBApplication::boardController->show(); UBApplication::boardController->show();
UBPlatformUtils::setDesktopMode(false); UBPlatformUtils::setDesktopMode(false);
mUninoteController->hideWindow(); mUninoteController->hideWindow();
mMainWindow->show(); mMainWindow->show();
@ -397,6 +397,32 @@ void UBApplicationController::showDocument()
emit mainModeChanged(Document); emit mainModeChanged(Document);
} }
void UBApplicationController::showSankoreWebDocument()
{
mMainWindow->webToolBar->hide();
mMainWindow->boardToolBar->hide();
mMainWindow->tutorialToolBar->hide();
mMainWindow->documentToolBar->show();
mMainMode = WebDocument;
adaptToolBar();
mirroringEnabled(false);
mMainWindow->switchToSankoreWebDocumentWidget();
UBApplication::documentController->hide();
mMainWindow->show();
mUninoteController->hideWindow();
emit mainModeChanged(WebDocument);
}
void UBApplicationController::showDesktop(bool dontSwitchFrontProcess) void UBApplicationController::showDesktop(bool dontSwitchFrontProcess)
{ {

@ -24,8 +24,7 @@ class UBApplicationController : public QObject
public: public:
UBApplicationController(UBBoardView *pControlView, UBBoardView *pDisplayView, UBApplicationController(UBBoardView *pControlView, UBBoardView *pDisplayView, UBMainWindow *pMainWindow, QObject* parent = 0);
UBMainWindow *pMainWindow, QObject* parent = 0);
virtual ~UBApplicationController(); virtual ~UBApplicationController();
int initialHScroll() { return mInitialHScroll; } int initialHScroll() { return mInitialHScroll; }
@ -53,6 +52,8 @@ class UBApplicationController : public QObject
void showDocument(); void showDocument();
void showSankoreWebDocument();
void showMessage(const QString& message, bool showSpinningWheel); void showMessage(const QString& message, bool showSpinningWheel);
void importFile(const QString& pFilePath); void importFile(const QString& pFilePath);
@ -69,7 +70,7 @@ class UBApplicationController : public QObject
enum MainMode enum MainMode
{ {
Board = 0, Internet, Document, Tutorial, ParaschoolEditor Board = 0, Internet, Document, Tutorial, ParaschoolEditor, WebDocument
}; };
MainMode displayMode() MainMode displayMode()

@ -117,7 +117,7 @@ void UBDisplayManager::setAsControl(QWidget* pControlWidget )
mControlWidget->showFullScreen(); mControlWidget->showFullScreen();
// !!!! Should be included into Windows after QT recompilation // !!!! Should be included into Windows after QT recompilation
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
mControlWidget->setAttribute(Qt::WA_MacNoShadow); // mControlWidget->setAttribute(Qt::WA_MacNoShadow);
#endif #endif
} }
} }
@ -133,7 +133,7 @@ void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget)
mDisplayWidget->showFullScreen(); mDisplayWidget->showFullScreen();
// !!!! Should be included into Windows after QT recompilation // !!!! Should be included into Windows after QT recompilation
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
mDisplayWidget->setAttribute(Qt::WA_MacNoShadow); // mDisplayWidget->setAttribute(Qt::WA_MacNoShadow);
#endif #endif
} }
} }

@ -29,6 +29,7 @@
#include "UBPersistenceManager.h" #include "UBPersistenceManager.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include "../adaptors/UBExportWeb.h"
UBDocumentManager* UBDocumentManager::sDocumentManager = 0; UBDocumentManager* UBDocumentManager::sDocumentManager = 0;
@ -53,9 +54,12 @@ UBDocumentManager::UBDocumentManager(QObject *parent)
UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this); UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this);
mExportAdaptors.append(exportFullPdf); mExportAdaptors.append(exportFullPdf);
UBExportDocument* exportDocument = new UBExportDocument(this); UBExportDocument* exportDocument = new UBExportDocument(this);
mExportAdaptors.append(exportDocument); mExportAdaptors.append(exportDocument);
// UBExportWeb* exportWeb = new UBExportWeb(this);
// mExportAdaptors.append(exportWeb);
UBWebPublisher* webPublished = new UBWebPublisher(this);
mExportAdaptors.append(webPublished);
UBImportDocument* documentImport = new UBImportDocument(this); UBImportDocument* documentImport = new UBImportDocument(this);
mImportAdaptors.append(documentImport); mImportAdaptors.append(documentImport);

@ -1000,7 +1000,7 @@ void UBPersistenceManager::checkIfDocumentRepositoryExists()
QMessageBox::question( QMessageBox::question(
QApplication::activeWindow(), QApplication::activeWindow(),
tr("Document Repository Loss"), 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); QMessageBox::Yes);
UBApplication::quit(); UBApplication::quit();

@ -7,7 +7,7 @@
class UBDocumentProxy; class UBDocumentProxy;
class UBGraphicsScene; class UBGraphicsScene;
class UBGraphicsScene::SceneViewState; class UBGraphicsScene;
class UBSceneCacheID class UBSceneCacheID
{ {

@ -54,9 +54,14 @@ void ub_message_output(QtMsgType type, const char *msg) {
int main(int argc, char *argv[]) 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) #if defined(_MSC_VER) && defined(_DEBUG)
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif #endif
*/
Q_INIT_RESOURCE(sankore); Q_INIT_RESOURCE(sankore);

@ -64,7 +64,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent)
mTransparentDrawingView->setAttribute(Qt::WA_TranslucentBackground, true); mTransparentDrawingView->setAttribute(Qt::WA_TranslucentBackground, true);
// !!!! Should be included into Windows after QT recompilation // !!!! Should be included into Windows after QT recompilation
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
mTransparentDrawingView->setAttribute(Qt::WA_MacNoShadow, true); //mTransparentDrawingView->setAttribute(Qt::WA_MacNoShadow, true);
#endif #endif
mTransparentDrawingView->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Window); mTransparentDrawingView->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Window);
mTransparentDrawingView->setCacheMode(QGraphicsView::CacheNone); mTransparentDrawingView->setCacheMode(QGraphicsView::CacheNone);

@ -1446,7 +1446,7 @@ bool UBDocumentController::isOKToOpenDocument(UBDocumentProxy* proxy)
else else
{ {
if (QMessageBox::question( 0, tr("Open Document"), 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(proxy->metaData(UBSettings::documentName).toString())
.arg(docVersion), .arg(docVersion),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)

@ -33,10 +33,10 @@ class UBDocumentController : public QObject
QWidget* controlView(); QWidget* controlView();
UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy); UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy);
bool addFileToDocument(UBDocumentProxy* document); bool addFileToDocument(UBDocumentProxy* document);
UBDocumentProxy* getCurrentDocument(); UBDocumentProxy* getCurrentDocument();
signals: signals:
void refreshThumbnails(); void refreshThumbnails();
void exportDone(); void exportDone();
public slots: public slots:
@ -91,7 +91,7 @@ class UBDocumentController : public QObject
UBDocumentToolsPalette *mToolsPalette; UBDocumentToolsPalette *mToolsPalette;
bool mToolsPalettePositionned; bool mToolsPalettePositionned;
UBDocumentGroupTreeItem* mTrashTi; UBDocumentGroupTreeItem* mTrashTi;
UBDocumentProxy* mCurrentDocument; UBDocumentProxy* mCurrentDocument;
private slots: private slots:
void documentZoomSliderValueChanged (int value); void documentZoomSliderValueChanged (int value);

@ -57,6 +57,7 @@ qreal UBGraphicsScene::toolLayerStart = 10000000.0;
qreal UBGraphicsScene::toolOffsetRuler = 100; qreal UBGraphicsScene::toolOffsetRuler = 100;
qreal UBGraphicsScene::toolOffsetProtractor = 100; qreal UBGraphicsScene::toolOffsetProtractor = 100;
qreal UBGraphicsScene::toolOffsetTriangle = 100;
qreal UBGraphicsScene::toolOffsetCompass = 100; qreal UBGraphicsScene::toolOffsetCompass = 100;
qreal UBGraphicsScene::toolOffsetEraser = 200; qreal UBGraphicsScene::toolOffsetEraser = 200;
@ -126,7 +127,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
UBGraphicsScene::~UBGraphicsScene() UBGraphicsScene::~UBGraphicsScene()
{ {
int a = 13;
// NOOP // NOOP
} }
@ -1412,9 +1412,9 @@ void UBGraphicsScene::addProtractor(QPointF center)
void UBGraphicsScene::addTriangle(QPointF center) void UBGraphicsScene::addTriangle(QPointF center)
{ {
// Protractor // Triangle
/*
UBGraphicsTriangle* protractor = new UBGraphicsTriangle(); // mem : owned and destroyed by the scene UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); // mem : owned and destroyed by the scene
mTools << triangle; mTools << triangle;
triangle->setZValue(toolLayerStart + toolOffsetProtractor); triangle->setZValue(toolLayerStart + toolOffsetProtractor);
@ -1426,7 +1426,7 @@ void UBGraphicsScene::addTriangle(QPointF center)
triangle->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y()); triangle->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y());
triangle->setVisible(true); triangle->setVisible(true);
setModified(true);*/ setModified(true);
} }

@ -235,6 +235,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
static qreal toolOffsetProtractor; static qreal toolOffsetProtractor;
static qreal toolOffsetCompass; static qreal toolOffsetCompass;
static qreal toolOffsetCurtain; static qreal toolOffsetCurtain;
static qreal toolOffsetTriangle;
QSet<QGraphicsItem*> tools(){ return mTools;} QSet<QGraphicsItem*> tools(){ return mTools;}

@ -12,7 +12,6 @@
UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent) UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent)
: QGraphicsScene ( parent ) : QGraphicsScene ( parent )
{ {
int a = 13;
//NOOP //NOOP
} }

@ -56,6 +56,8 @@ QString UBPlatformUtils::preferredLanguage()
void UBPlatformUtils::runInstaller(const QString &installerFilePath) void UBPlatformUtils::runInstaller(const QString &installerFilePath)
{ {
// TODO UB 4.x - auto update & installer are deactivated on Linux // TODO UB 4.x - auto update & installer are deactivated on Linux
Q_UNUSED(installerFilePath);
} }
void UBPlatformUtils::bringPreviousProcessToFront() void UBPlatformUtils::bringPreviousProcessToFront()
@ -77,6 +79,8 @@ QString UBPlatformUtils::computerName()
void UBPlatformUtils::setWindowNonActivableFlag(QWidget* widget, bool nonAcivable) void UBPlatformUtils::setWindowNonActivableFlag(QWidget* widget, bool nonAcivable)
{ {
Q_UNUSED(widget);
Q_UNUSED(nonAcivable);
} }
@ -84,6 +88,7 @@ void UBPlatformUtils::setWindowNonActivableFlag(QWidget* widget, bool nonAcivabl
void UBPlatformUtils::setDesktopMode(bool desktop) void UBPlatformUtils::setDesktopMode(bool desktop)
{ {
// NOOP // NOOP
Q_UNUSED(desktop);
} }
const KEYBT ENGLISH_LOCALE[] = { const KEYBT ENGLISH_LOCALE[] = {

@ -46,8 +46,8 @@ void UBPlatformUtils::init()
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *currentPath = [[NSBundle mainBundle] pathForResource:@"Save PDF to Uniboard" ofType:@"workflow"]; NSString *currentPath = [[NSBundle mainBundle] pathForResource:@"Save PDF to Sankore" ofType:@"workflow"];
NSString *installedPath = [[[@"~/Library/PDF Services" stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Save PDF to Uniboard"] stringByAppendingPathExtension:@"workflow"]; NSString *installedPath = [[[@"~/Library/PDF Services" stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Save PDF to Sankore"] stringByAppendingPathExtension:@"workflow"];
NSString *currentVersion = bundleShortVersion([NSBundle bundleWithPath:currentPath]); NSString *currentVersion = bundleShortVersion([NSBundle bundleWithPath:currentPath]);
NSString *installedVersion = bundleShortVersion([NSBundle bundleWithPath:installedPath]); NSString *installedVersion = bundleShortVersion([NSBundle bundleWithPath:installedPath]);
@ -59,7 +59,7 @@ void UBPlatformUtils::init()
BOOL copyOK = [fileManager copyPath:currentPath toPath:installedPath handler:nil]; BOOL copyOK = [fileManager copyPath:currentPath toPath:installedPath handler:nil];
if (!copyOK) if (!copyOK)
{ {
qWarning("Could not install the 'Save PDF to Uniboard' workflow"); qWarning("Could not install the 'Save PDF to Sankore' workflow");
} }
} }

@ -38,7 +38,7 @@ UBDockPalette::UBDockPalette(QWidget *parent, const char *name)
// !!!! Should be included into Windows after QT recompilation // !!!! Should be included into Windows after QT recompilation
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
setAttribute(Qt::WA_MacNoShadow); //setAttribute(Qt::WA_MacNoShadow);
#endif #endif
} }

@ -12,8 +12,8 @@
UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent) UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent)
: QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint))
, mIsMoving(false)
, mCustomPosition(false) , mCustomPosition(false)
, mIsMoving(false)
, mCanBeMinimized(false) , mCanBeMinimized(false)
, mMinimizedLocation(eMinimizedLocation_None) , mMinimizedLocation(eMinimizedLocation_None)
, mDefaultPosition(position) , mDefaultPosition(position)
@ -27,14 +27,14 @@ UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent)
else else
{ {
// standalone window // standalone window
// !!!! Should be included into Windows after QT recompilation // !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN #ifndef Q_WS_WIN
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_MacAlwaysShowToolWindow); setAttribute(Qt::WA_MacAlwaysShowToolWindow);
#endif #endif
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
setAttribute(Qt::WA_MacNonActivatingToolWindow); //setAttribute(Qt::WA_MacNonActivatingToolWindow);
setAttribute(Qt::WA_MacNoShadow); //setAttribute(Qt::WA_MacNoShadow);
#endif #endif
} }

@ -68,13 +68,13 @@ class UBFloatingPalette : public QWidget
QList<UBFloatingPalette*> mAssociatedPalette; QList<UBFloatingPalette*> mAssociatedPalette;
QPoint mDragPosition; QPoint mDragPosition;
bool mCanBeMinimized; bool mCanBeMinimized;
eMinimizedLocation mMinimizedLocation; eMinimizedLocation mMinimizedLocation;
Qt::Corner mDefaultPosition; Qt::Corner mDefaultPosition;
signals: signals:
void mouseEntered(); void mouseEntered();
void minimizeStart(eMinimizedLocation location); void minimizeStart(eMinimizedLocation location);
void maximizeStart(); void maximizeStart();
void maximized(); void maximized();
}; };

@ -17,303 +17,303 @@
/* /*
UBKeyboardPalette UBKeyboardPalette
*/ */
UBKeyboardPalette::UBKeyboardPalette(QWidget *parent) UBKeyboardPalette::UBKeyboardPalette(QWidget *parent)
: UBFloatingPalette(Qt::TopRightCorner, parent) : UBFloatingPalette(Qt::TopRightCorner, parent)
{ {
setCustomPosition(true); setCustomPosition(true);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
setFocusPolicy(Qt::NoFocus); setFocusPolicy(Qt::NoFocus);
capsLock = false; capsLock = false;
languagePopupActive = false; languagePopupActive = false;
keyboardActive = false; keyboardActive = false;
btnWidth = btnHeight = 16; btnWidth = btnHeight = 16;
buttons = new UBKeyButton*[47]; buttons = new UBKeyButton*[47];
for(int i=0; i<47; i++) for (int i=0; i<47; i++)
{ {
buttons[i] = new UBKeyButton(this); buttons[i] = new UBKeyButton(this);
} }
locales = UBPlatformUtils::getKeyboardLayouts(this->nLocalesCount); locales = UBPlatformUtils::getKeyboardLayouts(this->nLocalesCount);
createCtrlButtons(); createCtrlButtons();
nCurrentLocale = 0; nCurrentLocale = 0;
setInput(locales[nCurrentLocale]); setInput(locales[nCurrentLocale]);
setContentsMargins(radius() + 15, 4, radius() + 15, 4); setContentsMargins(radius() + 15, 4, radius() + 15, 4);
connect(this, SIGNAL(keyboardActivated(bool)), this, SLOT(onActivated(bool))); connect(this, SIGNAL(keyboardActivated(bool)), this, SLOT(onActivated(bool)));
} }
QList<UBKeyboardPalette*> UBKeyboardPalette::instances; QList<UBKeyboardPalette*> UBKeyboardPalette::instances;
UBKeyboardPalette* UBKeyboardPalette::create(QWidget *parent) UBKeyboardPalette* UBKeyboardPalette::create(QWidget *parent)
{ {
if (!UBPlatformUtils::hasVirtualKeyboard()) if (!UBPlatformUtils::hasVirtualKeyboard())
return NULL; return NULL;
UBKeyboardPalette* instance = new UBKeyboardPalette(parent); UBKeyboardPalette* instance = new UBKeyboardPalette(parent);
instances.append(instance); instances.append(instance);
instance->setKeyButtonSize(UBSettings::settings()->boardKeyboardPaletteKeyBtnSize->get().toString()); instance->setKeyButtonSize(UBSettings::settings()->boardKeyboardPaletteKeyBtnSize->get().toString());
instance->setAutoMinimize(UBSettings::settings()->boardKeyboardPaletteAutoMinimize->get().toBool()); instance->setAutoMinimize(UBSettings::settings()->boardKeyboardPaletteAutoMinimize->get().toBool());
instance->setVisible(false); instance->setVisible(false);
connect(UBSettings::settings()->boardKeyboardPaletteAutoMinimize , SIGNAL(changed(QVariant)), instance, SLOT(keyboardPaletteAutoMinimizeChanged(QVariant))); connect(UBSettings::settings()->boardKeyboardPaletteAutoMinimize , SIGNAL(changed(QVariant)), instance, SLOT(keyboardPaletteAutoMinimizeChanged(QVariant)));
connect(UBSettings::settings()->boardKeyboardPaletteKeyBtnSize, SIGNAL(changed(QVariant)), instance, SLOT(keyboardPaletteButtonSizeChanged(QVariant))); connect(UBSettings::settings()->boardKeyboardPaletteKeyBtnSize, SIGNAL(changed(QVariant)), instance, SLOT(keyboardPaletteButtonSizeChanged(QVariant)));
foreach(UBKeyboardPalette* inst, instances) foreach(UBKeyboardPalette* inst, instances)
{ {
connect(inst, SIGNAL(moved(const QPoint&)), instance, SLOT(syncPosition(const QPoint&))); connect(inst, SIGNAL(moved(const QPoint&)), instance, SLOT(syncPosition(const QPoint&)));
connect(instance, SIGNAL(moved(const QPoint&)), inst, SLOT(syncPosition(const QPoint&))); connect(instance, SIGNAL(moved(const QPoint&)), inst, SLOT(syncPosition(const QPoint&)));
connect(inst, SIGNAL(localeChanged(int)), instance, SLOT(syncLocale(int))); connect(inst, SIGNAL(localeChanged(int)), instance, SLOT(syncLocale(int)));
connect(instance, SIGNAL(localeChanged(int)), inst, SLOT(syncLocale(int))); connect(instance, SIGNAL(localeChanged(int)), inst, SLOT(syncLocale(int)));
} }
return instance; return instance;
} }
void UBKeyboardPalette::syncPosition(const QPoint & pos) void UBKeyboardPalette::syncPosition(const QPoint & pos)
{ {
move(pos); move(pos);
} }
void UBKeyboardPalette::syncLocale(int nLocale) void UBKeyboardPalette::syncLocale(int nLocale)
{ {
nCurrentLocale = nLocale; nCurrentLocale = nLocale;
setInput(locales[nCurrentLocale]); setInput(locales[nCurrentLocale]);
} }
void UBKeyboardPalette::keyboardPaletteAutoMinimizeChanged(QVariant b) void UBKeyboardPalette::keyboardPaletteAutoMinimizeChanged(QVariant b)
{ {
setAutoMinimize(b.toBool()); setAutoMinimize(b.toBool());
} }
void UBKeyboardPalette::keyboardPaletteButtonSizeChanged(QVariant size) void UBKeyboardPalette::keyboardPaletteButtonSizeChanged(QVariant size)
{ {
setKeyButtonSize(size.toString()); setKeyButtonSize(size.toString());
} }
void UBKeyboardPalette::setInput(const UBKeyboardLocale* locale) void UBKeyboardPalette::setInput(const UBKeyboardLocale* locale)
{ {
if (locale!=NULL) if (locale!=NULL)
{ {
for(int i=0; i<47; i++) for (int i=0; i<47; i++)
buttons[i]->setKeyBt((*locale)[i]); buttons[i]->setKeyBt((*locale)[i]);
} }
else else
{ {
this->hide(); this->hide();
} }
} }
UBKeyboardPalette::~UBKeyboardPalette() UBKeyboardPalette::~UBKeyboardPalette()
{ {
for(int i=0; i<47; i++) for (int i=0; i<47; i++)
delete buttons[i]; delete buttons[i];
delete [] buttons; delete [] buttons;
for(int i=0; i<8; i++) for (int i=0; i<8; i++)
delete ctrlButtons[i]; delete ctrlButtons[i];
delete [] ctrlButtons; delete [] ctrlButtons;
if (locales!=NULL) if (locales!=NULL)
{ {
for(int i=0; i<nLocalesCount; i++) for (int i=0; i<nLocalesCount; i++)
delete locales[i]; delete locales[i];
delete [] locales; delete [] locales;
} }
} }
QSize UBKeyboardPalette::sizeHint () const QSize UBKeyboardPalette::sizeHint () const
{ {
if ((autoMinimize && keyboardActive) || !autoMinimize) if ((autoMinimize && keyboardActive) || !autoMinimize)
{ {
int w = contentsMargins().left() + contentsMargins().right() + 13 + 14.5 * btnWidth; int w = contentsMargins().left() + contentsMargins().right() + 13 + 14.5 * btnWidth;
int h = contentsMargins().top() + contentsMargins().bottom() + 5 * btnHeight + 4; int h = contentsMargins().top() + contentsMargins().bottom() + 5 * btnHeight + 4;
return QSize(w, h); return QSize(w, h);
} }
else else
{ {
int MIN_WITH = 4, int MIN_WITH = 4,
MIN_HEIGTH = 4; MIN_HEIGTH = 4;
int w = contentsMargins().left() + contentsMargins().right() + 13 + 14.5 * MIN_WITH; int w = contentsMargins().left() + contentsMargins().right() + 13 + 14.5 * MIN_WITH;
int h = contentsMargins().top() + contentsMargins().bottom() + 5 * MIN_HEIGTH + 4; int h = contentsMargins().top() + contentsMargins().bottom() + 5 * MIN_HEIGTH + 4;
return QSize(w, h); return QSize(w, h);
} }
} }
const QString* UBKeyboardPalette::getLocaleName() const QString* UBKeyboardPalette::getLocaleName()
{ {
if (locales==NULL) if (locales==NULL)
return NULL; return NULL;
return &(locales[nCurrentLocale]->name); return &(locales[nCurrentLocale]->name);
} }
void UBKeyboardPalette::setLocale(int nLocale) void UBKeyboardPalette::setLocale(int nLocale)
{ {
if (locales!=NULL) if (locales!=NULL)
{ {
nCurrentLocale = nLocale; nCurrentLocale = nLocale;
setInput(locales[nCurrentLocale]); setInput(locales[nCurrentLocale]);
onLocaleChanged(locales[nCurrentLocale]); onLocaleChanged(locales[nCurrentLocale]);
update(); update();
} }
emit localeChanged(nLocale); emit localeChanged(nLocale);
} }
void UBKeyboardPalette::setKeyButtonSize(const QString& strSize) void UBKeyboardPalette::setKeyButtonSize(const QString& strSize)
{ {
QStringList strs = strSize.split('x'); QStringList strs = strSize.split('x');
if (strs.size()==2) if (strs.size()==2)
{ {
btnWidth = strs[0].toInt(); btnWidth = strs[0].toInt();
btnHeight = strs[1].toInt(); btnHeight = strs[1].toInt();
adjustSizeAndPosition(); adjustSizeAndPosition();
} }
} }
void UBKeyboardPalette::setAutoMinimize(bool autoMinimize) void UBKeyboardPalette::setAutoMinimize(bool autoMinimize)
{ {
this->autoMinimize = autoMinimize; this->autoMinimize = autoMinimize;
adjustSizeAndPosition(); adjustSizeAndPosition();
} }
void UBKeyboardPalette::enterEvent ( QEvent * ) void UBKeyboardPalette::enterEvent ( QEvent * )
{ {
if (keyboardActive) if (keyboardActive)
return; return;
keyboardActive = true; keyboardActive = true;
adjustSizeAndPosition(); adjustSizeAndPosition();
emit keyboardActivated(true); emit keyboardActivated(true);
} }
void UBKeyboardPalette::leaveEvent ( QEvent * ) void UBKeyboardPalette::leaveEvent ( QEvent * )
{ {
if (languagePopupActive || !keyboardActive || mIsMoving) if (languagePopupActive || !keyboardActive || mIsMoving)
return; return;
keyboardActive = false; keyboardActive = false;
adjustSizeAndPosition(); adjustSizeAndPosition();
emit keyboardActivated(false); emit keyboardActivated(false);
} }
void UBKeyboardPalette::moveEvent ( QMoveEvent * event ) void UBKeyboardPalette::moveEvent ( QMoveEvent * event )
{ {
UBFloatingPalette::moveEvent(event); UBFloatingPalette::moveEvent(event);
emit moved(event->pos()); emit moved(event->pos());
} }
void UBKeyboardPalette::adjustSizeAndPosition(bool pUp) void UBKeyboardPalette::adjustSizeAndPosition(bool pUp)
{ {
QSize rSize = sizeHint(); QSize rSize = sizeHint();
if (rSize != size()) if (rSize != size())
{ {
int dx = (rSize.width() - size().width()) /2; int dx = (rSize.width() - size().width()) /2;
int dy = rSize.height() - size().height(); int dy = rSize.height() - size().height();
this->move(x()-dx, y() - dy); this->move(x()-dx, y() - dy);
this->resize(rSize.width(), rSize.height()); this->resize(rSize.width(), rSize.height());
} }
UBFloatingPalette::adjustSizeAndPosition(pUp); UBFloatingPalette::adjustSizeAndPosition(pUp);
} }
void UBKeyboardPalette::paintEvent( QPaintEvent* event) void UBKeyboardPalette::paintEvent( QPaintEvent* event)
{ {
UBFloatingPalette::paintEvent(event); UBFloatingPalette::paintEvent(event);
QRect r = this->geometry(); QRect r = this->geometry();
int lleft, ltop, lright, lbottom; int lleft, ltop, lright, lbottom;
getContentsMargins ( &lleft, &ltop, &lright, &lbottom ) ; getContentsMargins ( &lleft, &ltop, &lright, &lbottom ) ;
int btw = (r.width() - lleft - lright - 13) / 14.5; int btw = (r.width() - lleft - lright - 13) / 14.5;
int bth = (r.height() - ltop - lbottom -4) / 5; int bth = (r.height() - ltop - lbottom -4) / 5;
lleft = (r.width() - (btw * 14.5 + 13))/2; lleft = (r.width() - (btw * 14.5 + 13))/2;
ltop = (r.height() - (bth * 5 + 4)) / 2; ltop = (r.height() - (bth * 5 + 4)) / 2;
int off = lleft;; int off = lleft;;
for(int i = 0; i<13; i++) for (int i = 0; i<13; i++)
{ {
QRect cr(off, ltop, btw, bth); QRect cr(off, ltop, btw, bth);
buttons[i]->setGeometry(cr); buttons[i]->setGeometry(cr);
off += btw + 1; off += btw + 1;
} }
ctrlButtons[0]->setGeometry(off, ltop, btw * 1.5, bth); ctrlButtons[0]->setGeometry(off, ltop, btw * 1.5, bth);
off += btw * 1.5; off += btw * 1.5;
lright = off; lright = off;
ltop += bth + 1; ltop += bth + 1;
int lwidth = 12 * btw + 12 + btw * 1.3; int lwidth = 12 * btw + 12 + btw * 1.3;
off = (r.width() - lwidth) / 2; off = (r.width() - lwidth) / 2;
ctrlButtons[1]->setGeometry(off, ltop, btw * 1.3, bth); ctrlButtons[1]->setGeometry(off, ltop, btw * 1.3, bth);
off += btw * 1.3 + 1; off += btw * 1.3 + 1;
for(int i=0; i<12; i++) for (int i=0; i<12; i++)
{ {
QRect cr(off, ltop, btw, bth); QRect cr(off, ltop, btw, bth);
buttons[13 + i]->setGeometry(cr); buttons[13 + i]->setGeometry(cr);
off += btw + 1; off += btw + 1;
} }
ltop += bth + 1; ltop += bth + 1;
lwidth = 12 * btw + 12 + btw * 2; lwidth = 12 * btw + 12 + btw * 2;
off = (r.width() - lwidth) / 2; off = (r.width() - lwidth) / 2;
for(int i=0; i<12; i++) for (int i=0; i<12; i++)
{ {
QRect cr(off, ltop, btw, bth); QRect cr(off, ltop, btw, bth);
buttons[13 + 12 + i]->setGeometry(cr); buttons[13 + 12 + i]->setGeometry(cr);
off += btw + 1; off += btw + 1;
} }
ctrlButtons[2]->setGeometry(off, ltop, btw * 2, bth); ctrlButtons[2]->setGeometry(off, ltop, btw * 2, bth);
ltop += bth + 1; ltop += bth + 1;
lwidth = 12 * btw + 11; lwidth = 12 * btw + 11;
off = (r.width() - lwidth) / 2; off = (r.width() - lwidth) / 2;
ctrlButtons[3]->setGeometry(off, ltop, btw, bth); ctrlButtons[3]->setGeometry(off, ltop, btw, bth);
off+=btw+1; off+=btw+1;
for(int i=0; i<10; i++) for (int i=0; i<10; i++)
{ {
QRect cr(off, ltop, btw, bth); QRect cr(off, ltop, btw, bth);
buttons[13 + 12 + 12 + i]->setGeometry(cr); buttons[13 + 12 + 12 + i]->setGeometry(cr);
off += btw + 1; off += btw + 1;
} }
ctrlButtons[4]->setGeometry(r.x() + off, ltop, btw, bth); ctrlButtons[4]->setGeometry(r.x() + off, ltop, btw, bth);
ltop += bth + 1; ltop += bth + 1;
lwidth = 11 * btw + 2; lwidth = 11 * btw + 2;
off = (r.width() - lwidth) / 2; off = (r.width() - lwidth) / 2;
ctrlButtons[5]->setGeometry(off, ltop, btw, bth); ctrlButtons[5]->setGeometry(off, ltop, btw, bth);
ctrlButtons[6]->setGeometry(off + btw + 1, ltop, btw*9, bth); ctrlButtons[6]->setGeometry(off + btw + 1, ltop, btw*9, bth);
ctrlButtons[7]->setGeometry(off + btw*10 + 2, ltop, btw, bth); ctrlButtons[7]->setGeometry(off + btw*10 + 2, ltop, btw, bth);
} }
/* /*
UBKeyboardButton UBKeyboardButton
*/ */
UBKeyboardButton::UBKeyboardButton(UBKeyboardPalette* parent) UBKeyboardButton::UBKeyboardButton(UBKeyboardPalette* parent)
:QWidget(parent), :QWidget(parent),
bFocused(false), keyboard(parent),
bPressed(false), bFocused(false),
keyboard(parent) bPressed(false)
{ {
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
} }
UBKeyboardButton::~UBKeyboardButton() UBKeyboardButton::~UBKeyboardButton()
@ -321,48 +321,48 @@ UBKeyboardButton::~UBKeyboardButton()
void UBKeyboardButton::paintEvent(QPaintEvent*) void UBKeyboardButton::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
if (bPressed) if (bPressed)
painter.setBrush(QBrush(QColor(0, 0xcc, 0))); painter.setBrush(QBrush(QColor(0, 0xcc, 0)));
else if (bFocused) else if (bFocused)
painter.setBrush(QBrush(QColor(0xcc, 0, 0))); painter.setBrush(QBrush(QColor(0xcc, 0, 0)));
painter.drawRoundedRect(0, 0, width()-1, height()-1, 3, 3); painter.drawRoundedRect(0, 0, width()-1, height()-1, 3, 3);
this->paintContent(painter); this->paintContent(painter);
} }
void UBKeyboardButton::enterEvent ( QEvent*) void UBKeyboardButton::enterEvent ( QEvent*)
{ {
bFocused = true; bFocused = true;
update(); update();
} }
void UBKeyboardButton::leaveEvent ( QEvent*) void UBKeyboardButton::leaveEvent ( QEvent*)
{ {
bFocused = false; bFocused = false;
update(); update();
} }
void UBKeyboardButton::mousePressEvent ( QMouseEvent * event) void UBKeyboardButton::mousePressEvent ( QMouseEvent * event)
{ {
event->accept(); event->accept();
bPressed = true; bPressed = true;
update(); update();
this->onPress(); this->onPress();
} }
void UBKeyboardButton::mouseReleaseEvent ( QMouseEvent * ) void UBKeyboardButton::mouseReleaseEvent ( QMouseEvent * )
{ {
bPressed = false; bPressed = false;
update(); update();
this->onRelease(); this->onRelease();
} }
UBKeyButton::UBKeyButton(UBKeyboardPalette* parent) UBKeyButton::UBKeyButton(UBKeyboardPalette* parent)
:UBKeyboardButton(parent), :UBKeyboardButton(parent),
keybt(0) keybt(0)
{} {}
UBKeyButton::~UBKeyButton() UBKeyButton::~UBKeyButton()
@ -370,8 +370,8 @@ UBKeyButton::~UBKeyButton()
void UBKeyButton::onPress() void UBKeyButton::onPress()
{ {
if (keybt!=NULL) if (keybt!=NULL)
sendUnicodeSymbol(keybt->code1, keybt->code2, capsLock()); sendUnicodeSymbol(keybt->code1, keybt->code2, capsLock());
} }
void UBKeyButton::onRelease() void UBKeyButton::onRelease()
@ -380,19 +380,19 @@ void UBKeyButton::onRelease()
void UBKeyButton::paintContent(QPainter& painter) void UBKeyButton::paintContent(QPainter& painter)
{ {
if (keybt) if (keybt)
{ {
QString text(QChar(capsLock() ? keybt->symbol2 : keybt->symbol1)); QString text(QChar(capsLock() ? keybt->symbol2 : keybt->symbol1));
QRect textRect(rect().x()+2, rect().y()+2, rect().width()-4, rect().height()-4); QRect textRect(rect().x()+2, rect().y()+2, rect().width()-4, rect().height()-4);
painter.drawText(textRect, Qt::AlignCenter, text); painter.drawText(textRect, Qt::AlignCenter, text);
} }
} }
UBCntrlButton::UBCntrlButton(UBKeyboardPalette* parent, const QString& _label, int _code ) UBCntrlButton::UBCntrlButton(UBKeyboardPalette* parent, const QString& _label, int _code )
:UBKeyboardButton(parent), :UBKeyboardButton(parent),
label(_label), label(_label),
code(_code) code(_code)
{} {}
UBCntrlButton::~UBCntrlButton() UBCntrlButton::~UBCntrlButton()
@ -400,7 +400,7 @@ UBCntrlButton::~UBCntrlButton()
void UBCntrlButton::onPress() void UBCntrlButton::onPress()
{ {
sendControlSymbol(code); sendControlSymbol(code);
} }
void UBCntrlButton::onRelease() void UBCntrlButton::onRelease()
@ -408,11 +408,11 @@ void UBCntrlButton::onRelease()
void UBCntrlButton::paintContent(QPainter& painter) void UBCntrlButton::paintContent(QPainter& painter)
{ {
painter.drawText(rect(), Qt::AlignCenter, label); painter.drawText(rect(), Qt::AlignCenter, label);
} }
UBCapsLockButton::UBCapsLockButton(UBKeyboardPalette* parent) UBCapsLockButton::UBCapsLockButton(UBKeyboardPalette* parent)
:UBKeyboardButton(parent) :UBKeyboardButton(parent)
{} {}
UBCapsLockButton::~UBCapsLockButton() UBCapsLockButton::~UBCapsLockButton()
@ -420,8 +420,8 @@ UBCapsLockButton::~UBCapsLockButton()
void UBCapsLockButton::onPress() void UBCapsLockButton::onPress()
{ {
keyboard->capsLock = !keyboard->capsLock; keyboard->capsLock = !keyboard->capsLock;
keyboard->update(); keyboard->update();
} }
void UBCapsLockButton::onRelease() void UBCapsLockButton::onRelease()
@ -429,27 +429,27 @@ void UBCapsLockButton::onRelease()
void UBCapsLockButton::paintContent(QPainter& painter) void UBCapsLockButton::paintContent(QPainter& painter)
{ {
painter.drawText(rect(), Qt::AlignCenter, "^"); painter.drawText(rect(), Qt::AlignCenter, "^");
} }
UBLocaleButton::UBLocaleButton(UBKeyboardPalette* parent) UBLocaleButton::UBLocaleButton(UBKeyboardPalette* parent)
:UBKeyboardButton(parent) :UBKeyboardButton(parent)
{ {
localeMenu = new QMenu(this); localeMenu = new QMenu(this);
for(int i=0; i<parent->nLocalesCount; i++) for (int i=0; i<parent->nLocalesCount; i++)
{ {
QAction* action = (parent->locales[i]->icon!=NULL) ? QAction* action = (parent->locales[i]->icon!=NULL) ?
localeMenu->addAction(*parent->locales[i]->icon, parent->locales[i]->fullName) localeMenu->addAction(*parent->locales[i]->icon, parent->locales[i]->fullName)
: localeMenu->addAction(parent->locales[i]->fullName); : localeMenu->addAction(parent->locales[i]->fullName);
action->setData(QVariant(i)); action->setData(QVariant(i));
} }
} }
UBLocaleButton::~UBLocaleButton() UBLocaleButton::~UBLocaleButton()
{ {
delete localeMenu; delete localeMenu;
} }
void UBLocaleButton::onPress() void UBLocaleButton::onPress()
@ -458,19 +458,19 @@ void UBLocaleButton::onPress()
void UBLocaleButton::onRelease() void UBLocaleButton::onRelease()
{ {
keyboard->languagePopupActive = true; keyboard->languagePopupActive = true;
QAction* action = localeMenu->exec(mapToGlobal(QPoint(0,0))); QAction* action = localeMenu->exec(mapToGlobal(QPoint(0,0)));
keyboard->languagePopupActive = false; keyboard->languagePopupActive = false;
if (action!=NULL) if (action!=NULL)
{ {
int nLocale = action->data().toInt(); int nLocale = action->data().toInt();
keyboard->setLocale(nLocale); keyboard->setLocale(nLocale);
} }
} }
void UBLocaleButton::paintContent(QPainter& painter) void UBLocaleButton::paintContent(QPainter& painter)
{ {
const QString* localeName = keyboard->getLocaleName(); const QString* localeName = keyboard->getLocaleName();
if (localeName!=NULL) if (localeName!=NULL)
painter.drawText(rect(), Qt::AlignCenter, *localeName); painter.drawText(rect(), Qt::AlignCenter, *localeName);
} }

@ -41,7 +41,7 @@ void x11SendKey(Display *display, int keyCode, int modifiers)
// Get the root window for the current display. // Get the root window for the current display.
Window winRoot = XDefaultRootWindow(display); Window winRoot = XDefaultRootWindow(display);
if (winRoot==NULL) if (winRoot==0)
return; return;
// Find the window which has the current keyboard focus. // Find the window which has the current keyboard focus.

@ -69,16 +69,6 @@ UBLibNavigatorWidget::UBLibNavigatorWidget(QWidget *parent, const char *name):QW
*/ */
UBLibNavigatorWidget::~UBLibNavigatorWidget() UBLibNavigatorWidget::~UBLibNavigatorWidget()
{ {
//if(NULL != mLayout)
//{
// delete mLayout;
// mLayout = NULL;
//}
//if(NULL != mLibWidget)
//{
// delete mLibWidget;
// mLibWidget = NULL;
//}
if(NULL != mPathViewer) if(NULL != mPathViewer)
{ {
delete mPathViewer; delete mPathViewer;
@ -99,7 +89,7 @@ UBLibNavigatorWidget::~UBLibNavigatorWidget()
void UBLibNavigatorWidget::dropMe(const QMimeData *_data) void UBLibNavigatorWidget::dropMe(const QMimeData *_data)
{ {
// Forward the mime data to the library widget // Forward the mime data to the library widget
Q_UNUSED(_data);
} }
/** /**

@ -14,6 +14,7 @@ UBMainWindow::UBMainWindow(QWidget *parent, Qt::WindowFlags flags)
, mBoardWidget(0) , mBoardWidget(0)
, mWebWidget(0) , mWebWidget(0)
, mDocumentsWidget(0) , mDocumentsWidget(0)
, mSankoreWebDocumentWidget(0)
{ {
Ui::MainWindow::setupUi(this); Ui::MainWindow::setupUi(this);
@ -91,6 +92,19 @@ void UBMainWindow::switchToDocumentsWidget()
} }
} }
void UBMainWindow::addSankoreWebDocumentWidget(QWebView* pWidget)
{
if(!mSankoreWebDocumentWidget){
mSankoreWebDocumentWidget = pWidget;
mStackedLayout->addWidget(mSankoreWebDocumentWidget);
}
}
void UBMainWindow::switchToSankoreWebDocumentWidget()
{
if(mSankoreWebDocumentWidget)
mStackedLayout->setCurrentWidget(mSankoreWebDocumentWidget);
}
void UBMainWindow::keyPressEvent(QKeyEvent *event) void UBMainWindow::keyPressEvent(QKeyEvent *event)
{ {
QMainWindow::keyPressEvent(event); QMainWindow::keyPressEvent(event);

@ -5,6 +5,7 @@
#include <QMainWindow> #include <QMainWindow>
#include <QWidget> #include <QWidget>
#include <QWebView>
class QStackedLayout; class QStackedLayout;
@ -27,6 +28,9 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow
void addDocumentsWidget(QWidget *pWidget); void addDocumentsWidget(QWidget *pWidget);
void switchToDocumentsWidget(); void switchToDocumentsWidget();
void addSankoreWebDocumentWidget(QWebView* pWidget);
void switchToSankoreWebDocumentWidget();
public slots: public slots:
void onExportDone(); void onExportDone();
@ -45,6 +49,7 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow
QWidget *mBoardWidget; QWidget *mBoardWidget;
QWidget *mWebWidget; QWidget *mWebWidget;
QWidget *mDocumentsWidget; QWidget *mDocumentsWidget;
QWebView* mSankoreWebDocumentWidget;
}; };

@ -14,6 +14,7 @@
#include "UBCookieJar.h" #include "UBCookieJar.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBNetworkAccessManager *UBNetworkAccessManager::sNetworkAccessManager = 0; UBNetworkAccessManager *UBNetworkAccessManager::sNetworkAccessManager = 0;

@ -127,8 +127,9 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
qreal xscale = p->worldTransform().m11(); qreal xscale = p->worldTransform().m11();
qreal yscale = p->worldTransform().m22(); qreal yscale = p->worldTransform().m22();
bool bZoomChanged = false; bool bZoomChanged = false;
bool bFirstThumbnail = false;
if(mScaleX != xscale || mScaleY != yscale) if(fabs(mScaleX - xscale) > 0.1 || fabs(mScaleY - yscale) > 0.1)
{ {
mScaleX = xscale; mScaleX = xscale;
mScaleY = yscale; mScaleY = yscale;
@ -138,9 +139,14 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
// First verify if the thumbnails and the pages are generated // First verify if the thumbnails and the pages are generated
if(!bThumbGenerated) if(!bThumbGenerated)
{ {
if(pageNumber == 1)
{
bFirstThumbnail = true;
}
if(!mThumbMap[pageNumber - 1]) if(!mThumbMap[pageNumber - 1])
{ {
// Generate the thumbnail // Generate the thumbnail
mThumbs << *createPDFImage(pageNumber, xscale, yscale, bounds); mThumbs << *createPDFImage(pageNumber, xscale, yscale, bounds);
mThumbMap[pageNumber - 1] = true; mThumbMap[pageNumber - 1] = true;
@ -164,10 +170,9 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
} }
} }
// Warning: verify pagenumber
QImage pdfImage; QImage pdfImage;
if(!bThumbGenerated) if(!bThumbGenerated || bFirstThumbnail)
{ {
pdfImage = mThumbs.at(pageNumber - 1); pdfImage = mThumbs.at(pageNumber - 1);
} }
@ -176,8 +181,6 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
pdfImage = mNumPageToPageMap[pageNumber]; pdfImage = mNumPageToPageMap[pageNumber];
} }
pdfImage.rect();
QTransform savedTransform = p->worldTransform(); QTransform savedTransform = p->worldTransform();
p->resetTransform(); p->resetTransform();
QTime t; QTime t;

@ -338,7 +338,7 @@ void UBPodcastController::start()
} }
else else
{ {
videoFileName = mPodcastRecordingPath + "/" + tr("Uniboard Cast") + "." + mVideoEncoder->videoFileExtension(); videoFileName = mPodcastRecordingPath + "/" + tr("Sankore Cast") + "." + mVideoEncoder->videoFileExtension();
} }
videoFileName = UBFileSystemUtils::nextAvailableFileName(videoFileName, " "); videoFileName = UBFileSystemUtils::nextAvailableFileName(videoFileName, " ");

@ -1,11 +1,114 @@
#include "UBAbstractDrawRuler.h" #include "UBAbstractDrawRuler.h"
#include <QtSvg>
#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" #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);
const int UBAbstractDrawRuler::sLeftEdgeMargin = 10;
const int UBAbstractDrawRuler::sDegreeToQtAngleUnit = 16;
const int UBAbstractDrawRuler::sRotationRadius = 15;
const int UBAbstractDrawRuler::sPixelsPerMillimeter = 5;
const int UBAbstractDrawRuler::sFillTransparency = 127;
const int UBAbstractDrawRuler::sDrawTransparency = 192;
const int UBAbstractDrawRuler::sRoundingRadius = sLeftEdgeMargin / 2;
UBAbstractDrawRuler::UBAbstractDrawRuler() UBAbstractDrawRuler::UBAbstractDrawRuler()
: 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));
}
UBAbstractDrawRuler::~UBAbstractDrawRuler() UBAbstractDrawRuler::~UBAbstractDrawRuler()
{
}
QCursor UBAbstractDrawRuler::moveCursor() const
{
return Qt::SizeAllCursor;
}
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());
}

@ -3,18 +3,66 @@
#include <QtGui> #include <QtGui>
class UBGraphicsScene; class UBGraphicsScene;
class QGraphicsSvgItem;
class UBAbstractDrawRuler : public QObject class UBAbstractDrawRuler : public QObject
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBAbstractDrawRuler(); UBAbstractDrawRuler();
~UBAbstractDrawRuler(); ~UBAbstractDrawRuler();
virtual void StartLine(const QPointF& position, qreal width) = 0; void create(QGraphicsItem& item);
virtual void DrawLine(const QPointF& position, qreal width) = 0;
virtual void EndLine() = 0; virtual void StartLine(const QPointF& position, qreal width);
virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine();
signals:
void hidden();
protected:
void paint();
virtual UBGraphicsScene* scene() const = 0;
virtual void rotateAroundCenter(qreal angle) = 0;
virtual QPointF rotationCenter() const = 0;
virtual QRectF closeButtonRect() const = 0;
bool mShowButtons;
QGraphicsSvgItem* mCloseSvgItem;
qreal mAntiScaleRatio;
QPointF startDrawPosition;
QCursor moveCursor() 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;
static const int sDegreeToQtAngleUnit;
static const int sRotationRadius;
static const int sPixelsPerMillimeter;
static const int sFillTransparency;
static const int sDrawTransparency;
static const int sRoundingRadius;
}; };

@ -12,68 +12,50 @@
#include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsScene.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "board/UBDrawingController.h" #include "board/UBDrawingController.h"
#include "UBAbstractDrawRuler.h"
#include "core/memcheck.h" #include "core/memcheck.h"
const int UBGraphicsProtractor::sFillTransparency = 127; const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350);
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() UBGraphicsProtractor::UBGraphicsProtractor()
: QGraphicsEllipseItem(sDefaultRect) : QGraphicsEllipseItem(sDefaultRect)
, mCurrentTool(None) , mCurrentTool(None)
, mShowButtons(false) , mShowButtons(false)
, mCurrentAngle(0) , mCurrentAngle(0)
, mSpan(180) , mSpan(180)
, mStartAngle(0) , mStartAngle(0)
, mScaleFactor(1) , mScaleFactor(1)
, mCloseSvgItem(0) , mResetSvgItem(0)
, mResetSvgItem(0) , mResizeSvgItem(0)
, mResizeSvgItem(0) , mMarkerSvgItem(0)
, mRotateSvgItem(0)
, mMarkerSvgItem(0)
{ {
setFlag(QGraphicsItem::ItemIsMovable, true); sFillTransparency = 127;
setFlag(QGraphicsItem::ItemIsSelectable, true); sDrawTransparency = 192;
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); create(*this);
setAcceptsHoverEvents(true);
setCacheMode(QGraphicsItem::DeviceCoordinateCache); setCacheMode(QGraphicsItem::DeviceCoordinateCache);
setStartAngle(0); setStartAngle(0);
setSpanAngle(180 * 16); 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 = new QGraphicsSvgItem(":/images/resetTool.svg", this);
mResetSvgItem->setVisible(false); mResetSvgItem->setVisible(false);
mResetSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mResetSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mResetSvgItem->setPos(resetButtonBounds().topLeft());
mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeTool.svg", this); mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeTool.svg", this);
mResizeSvgItem->setVisible(false); mResizeSvgItem->setVisible(false);
mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); 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());
mMarkerSvgItem = new QGraphicsSvgItem(":/images/angleMarker.svg", this); mMarkerSvgItem = new QGraphicsSvgItem(":/images/angleMarker.svg", this);
mMarkerSvgItem->setVisible(false); mMarkerSvgItem->setVisible(false);
mMarkerSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); mMarkerSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
mMarkerSvgItem->setPos(markerButtonBounds().topLeft());
mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this);
mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
scale(1.5, 1.5); scale(1.5, 1.5);
} }
@ -90,7 +72,7 @@ void UBGraphicsProtractor::paint(QPainter *painter, const QStyleOptionGraphicsIt
painter->setPen(drawColor()); painter->setPen(drawColor());
painter->setBrush(fillBrush()); painter->setBrush(fillBrush());
painter->drawPie(QRectF(rect().center().x() - radius(), rect().center().y() - radius(), painter->drawPie(QRectF(rect().center().x() - radius(), rect().center().y() - radius(),
2 * radius(), 2 * radius()), mStartAngle * 16, mSpan * 16); 2 * radius(), 2 * radius()), mStartAngle * 16, mSpan * 16);
paintGraduations(painter); paintGraduations(painter);
paintButtons(painter); paintButtons(painter);
paintAngleMarker(painter); paintAngleMarker(painter);
@ -120,9 +102,9 @@ QRectF UBGraphicsProtractor::boundingRect() const
qreal centerX = center.x(); qreal centerX = center.x();
qreal centerY = center.y(); qreal centerY = center.y();
QRectF bounds = resizeButtonBounds().adjusted(centerX, centerY, centerX, centerY); QRectF bounds = resizeButtonRect().adjusted(centerX, centerY, centerX, centerY);
bounds = bounds.united(closeButtonBounds().adjusted(centerX, centerY, centerX, centerY)); bounds = bounds.united(closeButtonRect().adjusted(centerX, centerY, centerX, centerY));
bounds = bounds.united(resetButtonBounds().adjusted(centerX, centerY, centerX, centerY)); bounds = bounds.united(resetButtonRect().adjusted(centerX, centerY, centerX, centerY));
QTransform t; QTransform t;
t.translate(centerX, centerY); t.translate(centerX, centerY);
@ -140,21 +122,21 @@ QPainterPath UBGraphicsProtractor::shape() const
{ {
QPainterPath path = QGraphicsEllipseItem::shape(); QPainterPath path = QGraphicsEllipseItem::shape();
QPainterPath buttonPath; QPainterPath buttonPath;
QRectF markerBounds = markerButtonBounds(); QRectF markerRect = markerButtonRect();
QPointF center = rect().center(); QPointF center = rect().center();
qreal centerX = center.x(); qreal centerX = center.x();
qreal centerY = center.y(); qreal centerY = center.y();
buttonPath.addRect(resizeButtonBounds().adjusted(centerX, centerY, centerX, centerY)); buttonPath.addRect(resizeButtonRect().adjusted(centerX, centerY, centerX, centerY));
if(!resizeButtonBounds().contains(markerBounds)) if (!resizeButtonRect().contains(markerRect))
{ {
buttonPath.addRect(markerBounds.adjusted(centerX - markerBounds.left() * 2 - markerBounds.width(), centerY buttonPath.addRect(markerRect.adjusted(centerX - markerRect.left() * 2 - markerRect.width(), centerY
, centerX - markerBounds.left() * 2 - markerBounds.width(), centerY)); , centerX - markerRect.left() * 2 - markerRect.width(), centerY));
buttonPath.addRect(markerBounds.adjusted(centerX, centerY, centerX, centerY)); buttonPath.addRect(markerRect.adjusted(centerX, centerY, centerX, centerY));
} }
buttonPath.addRect(closeButtonBounds().adjusted(centerX, centerY, centerX, centerY)); buttonPath.addRect(closeButtonRect().adjusted(centerX, centerY, centerX, centerY));
buttonPath.addRect(resetButtonBounds().adjusted(centerX, centerY, centerX, centerY)); buttonPath.addRect(resetButtonRect().adjusted(centerX, centerY, centerX, centerY));
QTransform t; QTransform t;
t.translate(centerX, centerY); t.translate(centerX, centerY);
t.rotate(-mStartAngle); t.rotate(-mStartAngle);
@ -188,44 +170,44 @@ void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
qreal angle = startLine.angleTo(currentLine); qreal angle = startLine.angleTo(currentLine);
qreal scaleFactor = currentLine.length()/startLine.length(); qreal scaleFactor = currentLine.length()/startLine.length();
switch(mCurrentTool) switch (mCurrentTool)
{ {
case Rotate : case Rotate :
prepareGeometryChange(); prepareGeometryChange();
mStartAngle = mStartAngle + angle; mStartAngle = mStartAngle + angle;
setStartAngle(mStartAngle * 16); setStartAngle(mStartAngle * 16);
mPreviousMousePos = currentPoint; mPreviousMousePos = currentPoint;
break; break;
case Resize : case Resize :
prepareGeometryChange(); prepareGeometryChange();
translate(rect().center().x(), rect().center().y()); translate(rect().center().x(), rect().center().y());
scale(scaleFactor, scaleFactor); scale(scaleFactor, scaleFactor);
translate(-rect().center().x(), -rect().center().y()); translate(-rect().center().x(), -rect().center().y());
mScaleFactor *= scaleFactor; mScaleFactor *= scaleFactor;
break; break;
case MoveMarker : case MoveMarker :
mCurrentAngle += angle; mCurrentAngle += angle;
if((int)mCurrentAngle % 360 > 270) if ((int)mCurrentAngle % 360 > 270)
mCurrentAngle = 0; mCurrentAngle = 0;
else if((int)mCurrentAngle % 360 >= 180) else if ((int)mCurrentAngle % 360 >= 180)
mCurrentAngle = 180; mCurrentAngle = 180;
mPreviousMousePos = currentPoint; mPreviousMousePos = currentPoint;
update(); update();
break; break;
case Move : case Move :
QGraphicsEllipseItem::mouseMoveEvent(event); QGraphicsEllipseItem::mouseMoveEvent(event);
break; break;
default : default :
break; break;
} }
if(mCurrentTool != Move) if (mCurrentTool != Move)
event->accept(); event->accept();
} }
@ -233,25 +215,25 @@ void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsProtractor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsProtractor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
switch(mCurrentTool) switch (mCurrentTool)
{ {
case Reset : case Reset :
setStartAngle(0); setStartAngle(0);
mStartAngle = 0; mStartAngle = 0;
break; break;
case Close : case Close :
hide(); hide();
emit hidden(); emit hidden();
break; break;
case MoveMarker : case MoveMarker :
update(); update();
break; break;
default : default :
QGraphicsEllipseItem::mouseReleaseEvent(event); QGraphicsEllipseItem::mouseReleaseEvent(event);
break; break;
} }
if (mCurrentTool != Move) if (mCurrentTool != Move)
@ -266,8 +248,8 @@ void UBGraphicsProtractor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsProtractor::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsProtractor::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector) if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
return; return;
if (!mShowButtons) if (!mShowButtons)
{ {
@ -297,8 +279,8 @@ void UBGraphicsProtractor::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void UBGraphicsProtractor::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsProtractor::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{ {
if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector) if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
return; return;
Tool currentTool = toolFromPos(event->pos()); Tool currentTool = toolFromPos(event->pos());
@ -308,7 +290,7 @@ void UBGraphicsProtractor::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
update(); update();
} }
if(currentTool == Move) if (currentTool == Move)
setCursor(Qt::SizeAllCursor); setCursor(Qt::SizeAllCursor);
else else
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
@ -323,47 +305,47 @@ qreal UBGraphicsProtractor::antiScale() const
} }
QRectF UBGraphicsProtractor::resetButtonBounds () const QRectF UBGraphicsProtractor::resetButtonRect () const
{ {
qreal antiSc = antiScale(); qreal antiSc = antiScale();
if(buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15) if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15)
return QRectF(-buttonSizeReference().width() * 7, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * 7, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
else else
return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
} }
QRectF UBGraphicsProtractor::closeButtonBounds () const QRectF UBGraphicsProtractor::closeButtonRect () const
{ {
qreal antiSc = antiScale(); qreal antiSc = antiScale();
if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 2) if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 2)
return QRectF(-buttonSizeReference().width() * 9, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * 9, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
else if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15) else if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15)
return QRectF(-buttonSizeReference().width() * 7 -buttonSizeReference().width() * antiSc, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * 7 -buttonSizeReference().width() * antiSc, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
else else
return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
} }
QRectF UBGraphicsProtractor::resizeButtonBounds () const QRectF UBGraphicsProtractor::resizeButtonRect () const
{ {
qreal antiSc = antiScale(); qreal antiSc = antiScale();
if(buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15) if (buttonSizeReference().width() * antiSc <= buttonSizeReference().width() * 15)
return QRectF(buttonSizeReference().width() * 8, -buttonSizeReference().height() * antiSc / 2, return QRectF(buttonSizeReference().width() * 8, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
else else
{ {
mResizeSvgItem->setZValue(zValue()+10); mResizeSvgItem->setZValue(zValue()+10);
return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2, return QRectF(-buttonSizeReference().width() * antiSc / 2, -buttonSizeReference().height() * antiSc / 2,
buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc); buttonSizeReference().width() * antiSc, buttonSizeReference().height() * antiSc);
} }
} }
@ -378,7 +360,7 @@ void UBGraphicsProtractor::paintGraduations(QPainter *painter)
QFont font1 = painter->font(); QFont font1 = painter->font();
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
font1.setPointSizeF(font1.pointSizeF() - 3); font1.setPointSizeF(font1.pointSizeF() - 3);
#endif #endif
QFontMetricsF fm1(font1); QFontMetricsF fm1(font1);
@ -392,21 +374,21 @@ void UBGraphicsProtractor::paintGraduations(QPainter *painter)
QPointF center = rect().center(); QPointF center = rect().center();
painter->drawArc(QRectF(center.x() - rad/2, center.y() - rad/2, rad, rad), mStartAngle*16, mSpan*16); painter->drawArc(QRectF(center.x() - rad/2, center.y() - rad/2, rad, rad), mStartAngle*16, mSpan*16);
for(int angle = 1; angle < mSpan; angle++) for (int angle = 1; angle < mSpan; angle++)
{ {
int graduationLength = (0 == angle % 10) ? tenDegreeGraduationLength : ((0 == angle % 5) ? fiveDegreeGraduationLength : oneDegreeGraduationLength); int graduationLength = (0 == angle % 10) ? tenDegreeGraduationLength : ((0 == angle % 5) ? fiveDegreeGraduationLength : oneDegreeGraduationLength);
qreal co = cos(((qreal)angle + mStartAngle) * PI/180); qreal co = cos(((qreal)angle + mStartAngle) * PI/180);
qreal si = sin(((qreal)angle + mStartAngle) * PI/180); qreal si = sin(((qreal)angle + mStartAngle) * PI/180);
if(0 == angle % 90) if (0 == angle % 90)
painter->drawLine(QLineF(QPointF(center.x(), center.y()), QPointF(center.x() + co*tenDegreeGraduationLength, center.y() - si*tenDegreeGraduationLength))); painter->drawLine(QLineF(QPointF(center.x(), center.y()), QPointF(center.x() + co*tenDegreeGraduationLength, center.y() - si*tenDegreeGraduationLength)));
//external arc //external arc
painter->drawLine(QLineF(QPointF(center.x()+ rad*co, center.y() - rad*si), painter->drawLine(QLineF(QPointF(center.x()+ rad*co, center.y() - rad*si),
QPointF(center.x()+ (rad - graduationLength)*co, center.y() - (rad - graduationLength)*si))); QPointF(center.x()+ (rad - graduationLength)*co, center.y() - (rad - graduationLength)*si)));
//internal arc //internal arc
painter->drawLine(QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si), painter->drawLine(QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si),
QPointF(center.x()+ (rad/2 + graduationLength)*co, QPointF(center.x()+ (rad/2 + graduationLength)*co,
center.y() - (rad/2 + graduationLength)*si))); center.y() - (rad/2 + graduationLength)*si)));
if (0 == angle % 10) if (0 == angle % 10)
{ {
@ -416,14 +398,14 @@ void UBGraphicsProtractor::paintGraduations(QPainter *painter)
QString grad2 = QString("%1").arg((int)(mSpan - angle)); QString grad2 = QString("%1").arg((int)(mSpan - angle));
painter->drawText(QRectF(center.x() + (rad - graduationLength*1.5)*co - fm1.width(grad)/2, painter->drawText(QRectF(center.x() + (rad - graduationLength*1.5)*co - fm1.width(grad)/2,
center.y() - (rad - graduationLength*1.5)*si - fm1.height()/2, center.y() - (rad - graduationLength*1.5)*si - fm1.height()/2,
fm1.width(grad), fm1.height()), Qt::AlignTop, grad); fm1.width(grad), fm1.height()), Qt::AlignTop, grad);
//internal arc //internal arc
painter->setFont(font2); painter->setFont(font2);
painter->drawText(QRectF(center.x() + (rad/2 + graduationLength*1.5)*co - fm2.width(grad2)/2, painter->drawText(QRectF(center.x() + (rad/2 + graduationLength*1.5)*co - fm2.width(grad2)/2,
center.y() - (rad/2 + graduationLength*1.5)*si - fm2.height()/2, center.y() - (rad/2 + graduationLength*1.5)*si - fm2.height()/2,
fm2.width(grad2), fm2.height()), Qt::AlignTop, grad2); fm2.width(grad2), fm2.height()), Qt::AlignTop, grad2);
painter->setFont(font1); painter->setFont(font1);
} }
@ -437,46 +419,46 @@ void UBGraphicsProtractor::paintButtons(QPainter *painter)
{ {
Q_UNUSED(painter); Q_UNUSED(painter);
if(mShowButtons) if (mShowButtons)
{ {
qreal antiSc = antiScale(); qreal antiSc = antiScale();
qreal scale = buttonSizeReference().width() / mCloseSvgItem->boundingRect().width(); qreal scale = buttonSizeReference().width() / mCloseSvgItem->boundingRect().width();
mCloseSvgItem->setPos(closeButtonBounds().topLeft() + rect().center()); mCloseSvgItem->setPos(closeButtonRect().topLeft() + rect().center());
mCloseSvgItem->resetTransform(); mCloseSvgItem->resetTransform();
mCloseSvgItem->translate(-closeButtonBounds().left(),-closeButtonBounds().top()); mCloseSvgItem->translate(-closeButtonRect().left(),-closeButtonRect().top());
mCloseSvgItem->rotate(-mStartAngle); 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... 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->resetTransform();
mResetSvgItem->translate(-resetButtonBounds().left(), -resetButtonBounds().top()); mResetSvgItem->translate(-resetButtonRect().left(), -resetButtonRect().top());
mResetSvgItem->rotate(-mStartAngle); 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... 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->resetTransform();
mResizeSvgItem->translate(-resizeButtonBounds().left(), -resizeButtonBounds().top()); mResizeSvgItem->translate(-resizeButtonRect().left(), -resizeButtonRect().top());
mResizeSvgItem->rotate(-mStartAngle); 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... 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->resetTransform();
mRotateSvgItem->translate(-rotateButtonBounds().left(), -rotateButtonBounds().top()); mRotateSvgItem->translate(-rotateButtonRect().left(), -rotateButtonRect().top());
mRotateSvgItem->rotate(-mStartAngle); 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... mRotateSvgItem->scale(scale, scale);//this do not impact the bounding box of thr svg item...
} }
qreal scale = markerSizeReference().width()/mMarkerSvgItem->boundingRect().width(); qreal scale = markerSizeReference().width()/mMarkerSvgItem->boundingRect().width();
mMarkerSvgItem->setPos(markerButtonBounds().topLeft() + rect().center()); mMarkerSvgItem->setPos(markerButtonRect().topLeft() + rect().center());
mMarkerSvgItem->resetTransform(); mMarkerSvgItem->resetTransform();
mMarkerSvgItem->translate(-markerButtonBounds().left(), -markerButtonBounds().top()); mMarkerSvgItem->translate(-markerButtonRect().left(), -markerButtonRect().top());
mMarkerSvgItem->rotate(- mStartAngle - mCurrentAngle); 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... mMarkerSvgItem->scale(scale, scale);//this do not impact the bounding box of thr svg item...
mCloseSvgItem->setVisible(mShowButtons); mCloseSvgItem->setVisible(mShowButtons);
@ -502,14 +484,14 @@ void UBGraphicsProtractor::paintAngleMarker(QPainter *painter)
painter->drawLine(QLineF(rect().center(), QPointF(rect().center().x()+ (rad+ 20)*co, rect().center().y() - (rad + 20)*si))); painter->drawLine(QLineF(rect().center(), QPointF(rect().center().x()+ (rad+ 20)*co, rect().center().y() - (rad + 20)*si)));
QPointF center = rect().center(); QPointF center = rect().center();
painter->drawArc(QRectF(center.x() - rad/8, center.y() - rad/8, rad / 4, rad / 4), 0 painter->drawArc(QRectF(center.x() - rad/8, center.y() - rad/8, rad / 4, rad / 4), 0
, (mCurrentAngle - (int)(mCurrentAngle/360)*360)*16); , (mCurrentAngle - (int)(mCurrentAngle/360)*360)*16);
painter->translate(rect().center()); painter->translate(rect().center());
painter->rotate(-mCurrentAngle); painter->rotate(-mCurrentAngle);
painter->translate(-rect().center().x(), -rect().center().y()); painter->translate(-rect().center().x(), -rect().center().y());
//Paint Angle text (horizontally) //Paint Angle text (horizontally)
//restore transformations //restore transformations
painter->translate(rect().center()); painter->translate(rect().center());
painter->rotate(mCurrentAngle); painter->rotate(mCurrentAngle);
painter->rotate(mStartAngle); painter->rotate(mStartAngle);
@ -517,23 +499,23 @@ void UBGraphicsProtractor::paintAngleMarker(QPainter *painter)
qreal angle = mCurrentAngle - (int)(mCurrentAngle/360)*360; qreal angle = mCurrentAngle - (int)(mCurrentAngle/360)*360;
if(angle != 0) if (angle != 0)
{ {
QString ang = QString("%1°").arg(angle,0, 'f', 1); QString ang = QString("%1°").arg(angle,0, 'f', 1);
QFont font2 = painter->font(); QFont font2 = painter->font();
font2.setBold(true); font2.setBold(true);
QFontMetricsF fm2(font2); QFontMetricsF fm2(font2);
painter->setFont(font2); painter->setFont(font2);
if (angle < 50) if (angle < 50)
angle = 90; angle = 90;
else else
angle = angle / 2; angle = angle / 2;
co = cos((mStartAngle + angle) * PI/180); co = cos((mStartAngle + angle) * PI/180);
si = sin((mStartAngle + angle) * PI/180); si = sin((mStartAngle + angle) * PI/180);
painter->drawText(QRectF(rect().center().x() + (rad*2.5/10)*co - fm2.width(ang)/2, painter->drawText(QRectF(rect().center().x() + (rad*2.5/10)*co - fm2.width(ang)/2,
rect().center().y() - (rad*2.5/10)*si - fm2.height()/2, rect().center().y() - (rad*2.5/10)*si - fm2.height()/2,
fm2.width(ang), fm2.height()), Qt::AlignTop, ang); fm2.width(ang), fm2.height()), Qt::AlignTop, ang);
} }
painter->restore(); painter->restore();
@ -550,17 +532,17 @@ UBGraphicsProtractor::Tool UBGraphicsProtractor::toolFromPos(QPointF pos)
t.rotate(mCurrentAngle); t.rotate(mCurrentAngle);
QPointF p2 = t.map(pos); QPointF p2 = t.map(pos);
if(resizeButtonBounds().contains(p1)) if (resizeButtonRect().contains(p1))
return Resize; return Resize;
else if(closeButtonBounds().contains(p1)) else if (closeButtonRect().contains(p1))
return Close; return Close;
else if(resetButtonBounds().contains(p1)) else if (resetButtonRect().contains(p1))
return Reset; return Reset;
else if(rotateButtonBounds().contains(p1)) else if (rotateButtonRect().contains(p1))
return Rotate; return Rotate;
else if(markerButtonBounds().contains(p2)) else if (markerButtonRect().contains(p2))
return MoveMarker; return MoveMarker;
else if(line.length() <= radius()) else if (line.length() <= radius())
return Move; return Move;
else else
return None; return None;
@ -572,15 +554,10 @@ UBGraphicsScene* UBGraphicsProtractor::scene() const
return static_cast<UBGraphicsScene*>(QGraphicsEllipseItem::scene()); return static_cast<UBGraphicsScene*>(QGraphicsEllipseItem::scene());
} }
QColor UBGraphicsProtractor::drawColor() const
{
return scene()->isDarkBackground() ? sDarkBackgroundDrawColor : sDrawColor;
}
QBrush UBGraphicsProtractor::fillBrush() const QBrush UBGraphicsProtractor::fillBrush() const
{ {
QColor fillColor = scene()->isDarkBackground() ? sDarkBackgroundFillColor : sFillColor; QColor fillColor = edgeFillColor();// scene()->isDarkBackground() ? sDarkBackgroundFillColor : sFillColor;
QColor fillColorCenter = scene()->isDarkBackground() ? sDarkBackgroundFillColorCenter : sFillColorCenter; QColor fillColorCenter = middleFillColor();//scene()->isDarkBackground() ? sDarkBackgroundFillColorCenter : sFillColorCenter;
QColor transparentWhite = Qt::white; QColor transparentWhite = Qt::white;
transparentWhite.setAlpha(scene()->isDarkBackground() ? sDrawTransparency : sFillTransparency); transparentWhite.setAlpha(scene()->isDarkBackground() ? sDrawTransparency : sFillTransparency);
QRadialGradient radialGradient(rect().center(), radius(), rect().center()); QRadialGradient radialGradient(rect().center(), radius(), rect().center());
@ -608,3 +585,14 @@ UBItem* UBGraphicsProtractor::deepCopy() const
return copy; return copy;
} }
void UBGraphicsProtractor::rotateAroundCenter(qreal angle)
{
Q_UNUSED(angle);
}
QPointF UBGraphicsProtractor::rotationCenter() const
{
return QPointF(rect().x(), rect().y());
}

@ -13,12 +13,12 @@
#include <QtSvg> #include <QtSvg>
#include "core/UB.h" #include "core/UB.h"
#include "tools/UBAbstractDrawRuler.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
class UBGraphicsScene; class UBGraphicsScene;
class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public UBItem class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipseItem, public UBItem
{ {
Q_OBJECT; Q_OBJECT;
@ -41,10 +41,6 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public
return Type; return Type;
} }
signals:
void hidden();
protected: protected:
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
@ -58,24 +54,24 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event);
virtual QPainterPath shape() const; virtual QPainterPath shape() const;
QRectF boundingRect() const; QRectF boundingRect() const;
private: private:
// Helpers // Helpers
void paintGraduations (QPainter *painter); void paintGraduations (QPainter *painter);
void paintButtons (QPainter *painter); void paintButtons (QPainter *painter);
void paintAngleMarker (QPainter *painter); void paintAngleMarker (QPainter *painter);
Tool toolFromPos (QPointF pos); Tool toolFromPos (QPointF pos);
qreal antiScale () const; qreal antiScale () const;
UBGraphicsScene* scene() const; UBGraphicsScene* scene() const;
QColor drawColor() const;
QBrush fillBrush() const; QBrush fillBrush() const;
QSizeF buttonSizeReference () const{return QSizeF(radius() / 10, mCloseSvgItem->boundingRect().height() * radius()/(10 * mCloseSvgItem->boundingRect().width()));} 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()));} QSizeF markerSizeReference () const{return QSizeF(radius() / 10, mMarkerSvgItem->boundingRect().height() * radius()/(10 * mMarkerSvgItem->boundingRect().width()));}
QRectF resetButtonBounds () const; QRectF resetButtonRect () const;
QRectF closeButtonBounds () const; QRectF closeButtonRect () const;
QRectF resizeButtonBounds () const; QRectF resizeButtonRect () const;
QRectF rotateButtonBounds () const{return QRectF(buttonSizeReference().width() * 5.5, -buttonSizeReference().width() * 5, buttonSizeReference().width(), buttonSizeReference().width());} QRectF rotateButtonRect () 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 markerButtonRect () const{return QRectF(radius() + 3, -markerSizeReference().height() / 2 , markerSizeReference().width(), markerSizeReference().height());}
inline qreal radius () const{return rect().height() / 2 - 20;} inline qreal radius () const{return rect().height() / 2 - 20;}
// Members // Members
@ -87,21 +83,18 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public
qreal mStartAngle; qreal mStartAngle;
qreal mScaleFactor; qreal mScaleFactor;
QGraphicsSvgItem* mCloseSvgItem;
QGraphicsSvgItem* mResetSvgItem; QGraphicsSvgItem* mResetSvgItem;
QGraphicsSvgItem* mResizeSvgItem; QGraphicsSvgItem* mResizeSvgItem;
QGraphicsSvgItem* mRotateSvgItem;
QGraphicsSvgItem* mMarkerSvgItem; QGraphicsSvgItem* mMarkerSvgItem;
QGraphicsSvgItem* mRotateSvgItem;
static const QRectF sDefaultRect;
virtual void rotateAroundCenter(qreal angle);
virtual QPointF rotationCenter() const;
static const int sFillTransparency; int sFillTransparency;
static const int sDrawTransparency; 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;
}; };
#endif /* UBGRAPHICSPROTRACTOR_H_ */ #endif /* UBGRAPHICSPROTRACTOR_H_ */

@ -17,48 +17,45 @@
#include "core/memcheck.h" #include "core/memcheck.h"
const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, 96); 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() UBGraphicsRuler::UBGraphicsRuler()
: QGraphicsRectItem() : QGraphicsRectItem()
, mResizing(false) , mResizing(false)
, mRotating(false) , mRotating(false)
, mShowButtons(false)
, mCloseSvgItem(0)
, mRotateSvgItem(0)
, mResizeSvgItem(0)
, mAntiScaleRatio(1.0)
{ {
setRect(sDefaultRect); setRect(sDefaultRect);
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setAcceptsHoverEvents(true);
mCloseSvgItem = new QGraphicsSvgItem(":/images/closeTool.svg", this); mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeRuler.svg", this);
mCloseSvgItem->setVisible(false); mResizeSvgItem->setVisible(false);
mCloseSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this); mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this);
mRotateSvgItem->setVisible(false); mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mResizeSvgItem = new QGraphicsSvgItem(":/images/resizeRuler.svg", this); create(*this);
mResizeSvgItem->setVisible(false);
mResizeSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
updateResizeCursor(); updateResizeCursor();
} }
void UBGraphicsRuler::updateResizeCursor()
{
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;
}
UBGraphicsRuler::~UBGraphicsRuler() UBGraphicsRuler::~UBGraphicsRuler()
{ {
// NOOP // NOOP
@ -83,22 +80,20 @@ void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *s
Q_UNUSED(styleOption); Q_UNUSED(styleOption);
Q_UNUSED(widget); Q_UNUSED(widget);
mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); UBAbstractDrawRuler::paint();
QTransform antiScaleTransform;
antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio);
mCloseSvgItem->setTransform(antiScaleTransform);
mCloseSvgItem->setPos(closeButtonRect().topLeft());
mRotateSvgItem->setTransform(antiScaleTransform);
mRotateSvgItem->setPos(rotateButtonRect().topLeft());
QTransform antiScaleTransform2; QTransform antiScaleTransform2;
qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0; qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0;
antiScaleTransform2.scale(ratio, 1.0); antiScaleTransform2.scale(ratio, 1.0);
mResizeSvgItem->setTransform(antiScaleTransform2); mResizeSvgItem->setTransform(antiScaleTransform2);
mResizeSvgItem->setPos(resizeButtonRect().topLeft()); mResizeSvgItem->setPos(resizeButtonRect().topLeft());
mRotateSvgItem->setTransform(antiScaleTransform2);
mRotateSvgItem->setPos(rotateButtonRect().topLeft());
painter->setPen(drawColor()); painter->setPen(drawColor());
painter->drawRoundedRect(rect(), sRoundingRadius, sRoundingRadius); painter->drawRoundedRect(rect(), sRoundingRadius, sRoundingRadius);
fillBackground(painter); fillBackground(painter);
@ -120,168 +115,6 @@ QVariant UBGraphicsRuler::itemChange(GraphicsItemChange change, const QVariant &
return QGraphicsRectItem::itemChange(change, value); 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) void UBGraphicsRuler::fillBackground(QPainter *painter)
{ {
QRectF rect1(rect().topLeft(), QSizeF(rect().width(), rect().height() / 4)); QRectF rect1(rect().topLeft(), QSizeF(rect().width(), rect().height() / 4));
@ -317,13 +150,13 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter)
QFontMetricsF fontMetrics(painter->font()); QFontMetricsF fontMetrics(painter->font());
for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++) for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++)
{ {
int graduationX = topLeftOrigin().x() + sPixelsPerMillimeter * millimeters; int graduationX = rotationCenter().x() + sPixelsPerMillimeter * millimeters;
int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ? int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ?
centimeterGraduationHeight : centimeterGraduationHeight :
((0 == millimeters % millimetersPerHalfCentimeter) ? ((0 == millimeters % millimetersPerHalfCentimeter) ?
halfCentimeterGraduationHeight : millimeterGraduationHeight); halfCentimeterGraduationHeight : millimeterGraduationHeight);
painter->drawLine(QLine(graduationX, topLeftOrigin().y(), graduationX, topLeftOrigin().y() + graduationHeight)); painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() + graduationHeight));
painter->drawLine(QLine(graduationX, topLeftOrigin().y() + rect().height(), graduationX, topLeftOrigin().y() + rect().height() - graduationHeight)); painter->drawLine(QLine(graduationX, rotationCenter().y() + rect().height(), graduationX, rotationCenter().y() + rect().height() - graduationHeight));
if (0 == millimeters % millimetersPerCentimeter) if (0 == millimeters % millimetersPerCentimeter)
{ {
QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter));
@ -346,44 +179,25 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter)
void UBGraphicsRuler::paintRotationCenter(QPainter *painter) void UBGraphicsRuler::paintRotationCenter(QPainter *painter)
{ {
painter->drawArc( painter->drawArc(
topLeftOrigin().x() - sRotationRadius, topLeftOrigin().y() - sRotationRadius, rotationCenter().x() - sRotationRadius, rotationCenter().y() - sRotationRadius,
2 * sRotationRadius, 2 * sRotationRadius, 2 * sRotationRadius, 2 * sRotationRadius,
270 * sDegreeToQtAngleUnit, 90 * sDegreeToQtAngleUnit); 270 * sDegreeToQtAngleUnit, 90 * sDegreeToQtAngleUnit);
} }
void UBGraphicsRuler::rotateAroundTopLeftOrigin(qreal angle) void UBGraphicsRuler::rotateAroundCenter(qreal angle)
{ {
QTransform transform; QTransform transform;
transform.translate(topLeftOrigin().x(), topLeftOrigin().y()); transform.translate(rotationCenter().x(), rotationCenter().y());
transform.rotate(angle); transform.rotate(angle);
transform.translate(- topLeftOrigin().x(), - topLeftOrigin().y()); transform.translate(- rotationCenter().x(), - rotationCenter().y());
setTransform(transform, true); setTransform(transform, true);
} }
QPointF UBGraphicsRuler::topLeftOrigin() const QPointF UBGraphicsRuler::rotationCenter() const
{ {
return QPointF(rect().x() + sLeftEdgeMargin, rect().y()); 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 QRectF UBGraphicsRuler::resizeButtonRect() const
{ {
@ -440,51 +254,165 @@ QRectF UBGraphicsRuler::rotateButtonRect() const
return QRectF(rotateRectTopLeft, rotateRectSize); return QRectF(rotateRectTopLeft, rotateRectSize);
} }
UBGraphicsScene* UBGraphicsRuler::scene() const void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{ {
return static_cast<UBGraphicsScene*>(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 (UBDrawingController::drawingController()->isDrawingTool())
{
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(rotationCenter(), event->pos());
QLineF lastLine(rotationCenter(), event->lastPos());
rotateAroundCenter(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();
update(QRectF(rotationCenter(), 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"); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
font.setPixelSize(16);
return font; 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"); mShowButtons = false;
QTransform itemTransform = sceneTransform(); setCursor(Qt::ArrowCursor);
QRectF itemRect = boundingRect(); mCloseSvgItem->setVisible(mShowButtons);
QPointF topLeft = itemTransform.map(itemRect.topLeft()); mResizeSvgItem->setVisible(mShowButtons);
QPointF topRight = itemTransform.map(itemRect.topRight()); mRotateSvgItem->setVisible(mShowButtons);
QLineF topLine(topLeft, topRight); UBDrawingController::drawingController()->mActiveRuler = NULL;
qreal angle = topLine.angle(); event->accept();
QTransform tr; update();
tr.rotate(- angle);
QCursor resizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
mResizeCursor = resizeCursor;
} }
QCursor UBGraphicsRuler::drawRulerLineCursor() const
UBGraphicsScene* UBGraphicsRuler::scene() const
{ {
return UBResources::resources()->drawLineRulerCursor; return static_cast<UBGraphicsScene*>(QGraphicsRectItem::scene());
} }
void UBGraphicsRuler::StartLine(const QPointF& scenePos, qreal width) void UBGraphicsRuler::StartLine(const QPointF& scenePos, qreal width)

@ -39,75 +39,51 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu
virtual void DrawLine(const QPointF& position, qreal width); virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine(); virtual void EndLine();
signals:
void hidden();
protected: protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
// Events // Events
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
private: private:
bool mResizing;
bool mRotating;
// Helpers // Helpers
void fillBackground(QPainter *painter); void fillBackground(QPainter *painter);
void paintGraduations(QPainter *painter); void paintGraduations(QPainter *painter);
void paintRotationCenter(QPainter *painter); void paintRotationCenter(QPainter *painter);
void rotateAroundTopLeftOrigin(qreal angle); virtual void rotateAroundCenter(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;
int drawLineDirection; QGraphicsSvgItem* mRotateSvgItem;
QGraphicsSvgItem* mResizeSvgItem;
// Members void updateResizeCursor();
bool mResizing; QCursor resizeCursor() const{return mResizeCursor;}
bool mRotating;
bool mShowButtons; virtual QPointF rotationCenter() const;
QGraphicsSvgItem* mCloseSvgItem; virtual QRectF resizeButtonRect() const;
QGraphicsSvgItem* mRotateSvgItem; virtual QRectF closeButtonRect() const;
QGraphicsSvgItem* mResizeSvgItem; virtual QRectF rotateButtonRect() const;
QCursor mResizeCursor; virtual UBGraphicsScene* scene() const;
qreal mAntiScaleRatio;
QPointF startDrawPosition; QCursor mResizeCursor;
int drawLineDirection;
// Constants // Constants
static const QRect sDefaultRect; static const QRect sDefaultRect;
static const int sLeftEdgeMargin = 10;
static const int sMinLength = 150; 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_ */ #endif /* UBGRAPHICSRULER_H_ */

@ -1,10 +1,555 @@
#include <QGraphicsPolygonItem>
#include <QPolygonF>
#include "tools/UBGraphicsTriangle.h" #include "tools/UBGraphicsTriangle.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "board/UBDrawingController.h"
#include "domain/UBGraphicsScene.h"
#include "core/memcheck.h" #include "core/memcheck.h"
const QRect UBGraphicsTriangle::sDefaultRect = QRect(0, 0, 800, 400);
const UBGraphicsTriangle::UBGraphicsTriangleOrientation UBGraphicsTriangle::sDefaultOrientation =
UBGraphicsTriangle::BottomLeft;
UBGraphicsTriangle::UBGraphicsTriangle() UBGraphicsTriangle::UBGraphicsTriangle()
: QGraphicsPolygonItem()
, UBAbstractDrawRuler()
, mResizing1(false)
, mResizing2(false)
, mRotating(false)
, angle(0)
{ {
setRect(sDefaultRect, sDefaultOrientation);
create(*this);
mHFlipSvgItem = new QGraphicsSvgItem(":/images/hflipTool.svg", this);
mHFlipSvgItem->setVisible(false);
mHFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mVFlipSvgItem = new QGraphicsSvgItem(":/images/vflipTool.svg", this);
mVFlipSvgItem->setVisible(false);
mVFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
mRotateSvgItem = new QGraphicsSvgItem(":/images/rotateTool.svg", this);
mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
//updateResizeCursor();
} }
UBGraphicsTriangle::~UBGraphicsTriangle() UBGraphicsTriangle::~UBGraphicsTriangle()
{} {
}
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)
{
QPolygonF polygon;
polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h) << QPoint(x, y);
setPolygon(polygon);
setOrientation(orientation);
}
void UBGraphicsTriangle::setOrientation(UBGraphicsTriangleOrientation orientation)
{
mOrientation = orientation;
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, boundingRect().right(), 0, 1);
break;
case TopLeft:
t.setMatrix(1, 0, 0, 0, -1, 0, 0, boundingRect().bottom(), 1);
break;
case TopRight:
t.setMatrix(-1, 0, 0, 0, -1, 0, boundingRect().right(), boundingRect().bottom(), 1);
break;
}
rotateAroundCenter(t);
setTransform(t);
}
UBGraphicsScene* UBGraphicsTriangle::scene() const
{
return static_cast<UBGraphicsScene*>(QGraphicsPolygonItem::scene());
}
void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
QPointF A1(rect().x(), rect().y());
QPointF B1(rect().x(), rect().y() + rect().height());
QPointF C1(rect().x() + rect().width(), rect().y() + rect().height());
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
qreal L = (C * d + rect().width() * d)/ rect().height();
qreal K = (C * d + rect().height() * d)/ rect().width();
qreal W1 = rect().height() * d / C;
qreal H1 = rect().width() * d / C;
QPointF A2(rect().x() + d, rect().y() + K);
QPointF B2(rect().x() + d, rect().y() + rect().height() - d);
QPointF C2(rect().x() + rect().width() - L, rect().y() + rect().height() - d);
QPoint CC(rect().x() + rect().width() - L + W1,
rect().y() + rect().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);
mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
QTransform antiScaleTransform;
antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio);
mCloseSvgItem->setTransform(antiScaleTransform);
mHFlipSvgItem->setTransform(antiScaleTransform);
mVFlipSvgItem->setTransform(antiScaleTransform);
mRotateSvgItem->setTransform(antiScaleTransform);
mCloseSvgItem->setPos(closeButtonRect().topLeft());
mHFlipSvgItem->setPos(hFlipRect().topLeft());
mVFlipSvgItem->setPos(vFlipRect().topLeft());
mRotateSvgItem->setPos(rotateRect().topLeft());
if (mShowButtons || mResizing1 || mResizing2)
{
painter->setBrush(QColor(0, 0, 0));
if (mShowButtons || mResizing1)
painter->drawPolygon(resize1Polygon());
if (mShowButtons || mResizing2)
painter->drawPolygon(resize2Polygon());
}
}
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 = rotationCenter().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 >= rotationCenter().y() - graduationHeight)
break;
painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() - 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::rotateAroundCenter(qreal angle)
{
this->angle = angle;
QTransform transform;
rotateAroundCenter(transform);
setTransform(transform, true);
}
void UBGraphicsTriangle::rotateAroundCenter(QTransform& transform)
{
transform.translate(rotationCenter().x(), rotationCenter().y());
transform.rotate(angle);
transform.translate(- rotationCenter().x(), - rotationCenter().y());
}
QPointF UBGraphicsTriangle::rotationCenter() const
{
return QPointF(rect().x() + sLeftEdgeMargin , rect().bottom());
}
QRectF UBGraphicsTriangle::closeButtonRect() const
{
return QRectF(rect().x() + d - mCloseSvgItem->boundingRect().width() - 5,
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - 5,
mCloseSvgItem->boundingRect().width(),
mCloseSvgItem->boundingRect().height());
}
QPolygonF UBGraphicsTriangle::resize1Polygon() const
{
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
QPolygonF p;
QPointF P1(rect().right() - sArrowLength, rect().bottom());
QPointF P2(rect().right() - sArrowLength * rect().width() / C,
rect().bottom() - sArrowLength * rect().height() / C );
p << QPointF(rect().right(), rect().bottom()) << P1 << P2;
return p;
}
QPolygonF UBGraphicsTriangle::resize2Polygon() const
{
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
QPolygonF p;
QPointF P1(rect().left(), rect().top() + sArrowLength);
QPointF P2(rect().left() + sArrowLength * rect().width() / C,
rect().top() + sArrowLength * rect().height() / C );
p << QPointF(rect().left(), rect().top()) << P1 << P2;
return p;
}
QRectF UBGraphicsTriangle::hFlipRect() const
{
return QRectF(rect().x() + d - mHFlipSvgItem->boundingRect().width() - 5,
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - mVFlipSvgItem->boundingRect().height() -
mVFlipSvgItem->boundingRect().height() - 15,
mHFlipSvgItem->boundingRect().width(),
mHFlipSvgItem->boundingRect().height());
}
QRectF UBGraphicsTriangle::vFlipRect() const
{
return QRectF(rect().x() + d - mVFlipSvgItem->boundingRect().width() - 5,
rect().bottom() - d - mCloseSvgItem->boundingRect().height() - mVFlipSvgItem->boundingRect().height() - 10,
mVFlipSvgItem->boundingRect().width(),
mVFlipSvgItem->boundingRect().height());
}
QRectF UBGraphicsTriangle::rotateRect() const
{
QPointF A1(rect().x(), rect().y());
QPointF B1(rect().x(), rect().y() + rect().height());
QPointF C1(rect().x() + rect().width(), rect().y() + rect().height());
qreal C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
qreal L = (C * d + rect().width() * d)/ rect().height();
QPointF C2(rect().x() + rect().width() - L, rect().y() + rect().height() - d);
return QRectF(C2 + QPointF(20, 5), QSizeF(mRotateSvgItem->boundingRect().size()));
}
QCursor UBGraphicsTriangle::moveResizeCursor() const
{
return Qt::OpenHandCursor;
}
QCursor UBGraphicsTriangle::flipCursor() const
{
return Qt::ArrowCursor;
}
void UBGraphicsTriangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
{
mResizing1 = true;
event->accept();
}
else if (resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
{
mResizing2 = true;
event->accept();
}
else if(rotateRect().contains(event->pos()))
{
mRotating = true;
event->accept();
}
else
{
QGraphicsItem::mousePressEvent(event);
}
mShowButtons = false;
mCloseSvgItem->setVisible(false);
mHFlipSvgItem->setVisible(false);
mVFlipSvgItem->setVisible(false);
mRotateSvgItem->setVisible(mRotating);
update();
}
void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (!mResizing1 && !mResizing2 && !mRotating)
{
QGraphicsItem::mouseMoveEvent(event);
}
else
{
if (mResizing1)
{
QPointF delta = event->pos() - event->lastPos();
if (rect().width() + delta.x() < sMinWidth)
delta.setX(sMinWidth - rect().width());
if (mOrientation == TopLeft || mOrientation == BottomLeft)
{
setRect(QRectF(
rect().topLeft(),
QSizeF(rect().width() + delta.x(),
rect().height())),
mOrientation);
}
else
{
setRect(
rect().left() - delta.x(),
rect().top(),
rect().width() + delta.x(),
rect().height(),
mOrientation
);
}
}
if (mResizing2)
{
QPointF delta = event->pos() - event->lastPos();
if (rect().height() + delta.y() < sMinHeight)
delta.setY(sMinHeight - rect().height());
qDebug() << delta;
setRect(QRect(
rect().left(),
rect().top() + delta.y(),
rect().width(),
rect().height() - delta.y()),
mOrientation);
}
if (mRotating)
{
QLineF currentLine(rotationCenter(), event->pos());
QLineF lastLine(rotationCenter(), event->lastPos());
rotateAroundCenter(currentLine.angleTo(lastLine));
}
event->accept();
}
}
void UBGraphicsTriangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (mResizing1 || mResizing2 || mRotating)
{
mResizing1 = false;
mResizing2 = false;
mRotating = false;
event->accept();
}
else if (closeButtonRect().contains(event->pos()))
{
hide();
emit hidden();
event->accept();
}
else if (hFlipRect().contains(event->pos()))
{
switch(mOrientation)
{
case BottomLeft:
setOrientation(BottomRight);
break;
case BottomRight:
setOrientation(BottomLeft);
break;
case TopLeft:
setOrientation(TopRight);
break;
case TopRight:
setOrientation(TopLeft);
break;
}
}
else if (vFlipRect().contains(event->pos()))
{
switch(mOrientation)
{
case BottomLeft:
setOrientation(TopLeft);
break;
case BottomRight:
setOrientation(TopRight);
break;
case TopLeft:
setOrientation(BottomLeft);
break;
case TopRight:
setOrientation(BottomRight);
break;
}
}
else
{
QGraphicsItem::mouseReleaseEvent(event);
}
mShowButtons = true;
update();
if (scene())
scene()->setModified(true);
}
void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
if (currentTool == UBStylusTool::Selector)
{
mCloseSvgItem->setParentItem(this);
mShowButtons = true;
mCloseSvgItem->setVisible(true);
mHFlipSvgItem->setVisible(true);
mVFlipSvgItem->setVisible(true);
mRotateSvgItem->setVisible(true);
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill) ||
resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
setCursor(moveResizeCursor());
else if (closeButtonRect().contains(event->pos()))
setCursor(closeCursor());
else if (hFlipRect().contains(event->pos())
|| vFlipRect().contains(event->pos()))
setCursor(flipCursor());
else if (rotateRect().contains(event->pos()))
setCursor(rotateCursor());
else
setCursor(moveCursor());
event->accept();
update();
}
}
void UBGraphicsTriangle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
mShowButtons = false;
setCursor(Qt::ArrowCursor);
mCloseSvgItem->setVisible(false);
mVFlipSvgItem->setVisible(false);
mHFlipSvgItem->setVisible(false);
mRotateSvgItem->setVisible(false);
event->accept();
update();
}
void UBGraphicsTriangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
if (currentTool == UBStylusTool::Selector)
{
mCloseSvgItem->setVisible(mShowButtons);
mVFlipSvgItem->setVisible(mShowButtons);
mHFlipSvgItem->setVisible(mShowButtons);
mRotateSvgItem->setVisible(mShowButtons);
if (resize1Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill) ||
resize2Polygon().containsPoint(event->pos().toPoint(), Qt::OddEvenFill))
setCursor(moveResizeCursor());
else if (closeButtonRect().contains(event->pos()))
setCursor(closeCursor());
else if (hFlipRect().contains(event->pos())
|| vFlipRect().contains(event->pos()))
setCursor(flipCursor());
else if (rotateRect().contains(event->pos()))
setCursor(rotateCursor());
else
setCursor(moveCursor());
event->accept();
}
}

@ -15,17 +15,107 @@
#include "core/UB.h" #include "core/UB.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#include "tools/UBAbstractDrawRuler.h"
class UBGraphicsScene; class UBGraphicsScene;
class UBItem;
class UBGraphicsTriangle : public QObject, public QGraphicsPolygonItem, public UBItem class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonItem, public UBItem
{ {
Q_OBJECT; Q_OBJECT;
public: public:
UBGraphicsTriangle(); UBGraphicsTriangle();
virtual ~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);
void setOrientation(UBGraphicsTriangleOrientation orientation);
QRectF rect() const {return boundingRect();}
UBGraphicsScene* scene() const;
protected:
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
virtual void rotateAroundCenter(qreal angle);
virtual QPointF rotationCenter() const;
virtual QRectF closeButtonRect() const;
QPolygonF resize1Polygon() const;
QPolygonF resize2Polygon() const;
QRectF hFlipRect() const;
QRectF vFlipRect() const;
QRectF rotateRect() const;
QCursor moveResizeCursor() const;
QCursor flipCursor() const;
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);
private:
QTransform calculateRotationTransform();
qreal angle;
void rotateAroundCenter(QTransform& transform);
bool mResizing1;
bool mResizing2;
bool mRotating;
QGraphicsSvgItem* mHFlipSvgItem;
QGraphicsSvgItem* mVFlipSvgItem;
QGraphicsSvgItem* mRotateSvgItem;
static const QRect sDefaultRect;
static const UBGraphicsTriangleOrientation sDefaultOrientation;
void paintGraduations(QPainter *painter);
UBGraphicsTriangleOrientation mOrientation;
static const int d = 70; // width of triangle border
static const int sArrowLength = 30;
static const int sMinWidth = 200;
static const int sMinHeight = 150;
}; };
#endif /* UBGRAPHICSTRIANGLE_H_ */ #endif /* UBGRAPHICSTRIANGLE_H_ */

@ -151,7 +151,7 @@ void WBWebPage::handleUnsupportedContent(QNetworkReply *reply)
if (isPDF) if (isPDF)
{ {
QMessageBox messageBox(mainWindow()); 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); messageBox.addButton(tr("Download"), QMessageBox::AcceptRole);
QAbstractButton *addButton = QAbstractButton *addButton =

Loading…
Cancel
Save