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. 394
      src/adaptors/publishing/UBDocumentPublisher.cpp
  13. 67
      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/UBLibraryController.cpp
  18. 8
      src/core/UBApplication.cpp
  19. 1
      src/core/UBApplication.h
  20. 32
      src/core/UBApplicationController.cpp
  21. 7
      src/core/UBApplicationController.h
  22. 4
      src/core/UBDisplayManager.cpp
  23. 6
      src/core/UBDocumentManager.cpp
  24. 2
      src/core/UBPersistenceManager.cpp
  25. 2
      src/core/UBSceneCache.h
  26. 5
      src/core/main.cpp
  27. 2
      src/desktop/UBDesktopAnnotationController.cpp
  28. 2
      src/document/UBDocumentController.cpp
  29. 10
      src/domain/UBGraphicsScene.cpp
  30. 1
      src/domain/UBGraphicsScene.h
  31. 1
      src/frameworks/UBCoreGraphicsScene.cpp
  32. 5
      src/frameworks/UBPlatformUtils_linux.cpp
  33. 6
      src/frameworks/UBPlatformUtils_mac.mm
  34. 2
      src/gui/UBDockPalette.cpp
  35. 6
      src/gui/UBFloatingPalette.cpp
  36. 4
      src/gui/UBKeyboardPalette.cpp
  37. 2
      src/gui/UBKeyboardPalette_linux.cpp
  38. 12
      src/gui/UBLibNavigatorWidget.cpp
  39. 14
      src/gui/UBMainWindow.cpp
  40. 5
      src/gui/UBMainWindow.h
  41. 1
      src/network/UBNetworkAccessManager.cpp
  42. 13
      src/pdf/XPDFRenderer.cpp
  43. 2
      src/podcast/UBPodcastController.cpp
  44. 103
      src/tools/UBAbstractDrawRuler.cpp
  45. 56
      src/tools/UBAbstractDrawRuler.h
  46. 124
      src/tools/UBGraphicsProtractor.cpp
  47. 37
      src/tools/UBGraphicsProtractor.h
  48. 422
      src/tools/UBGraphicsRuler.cpp
  49. 62
      src/tools/UBGraphicsRuler.h
  50. 547
      src/tools/UBGraphicsTriangle.cpp
  51. 92
      src/tools/UBGraphicsTriangle.h
  52. 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");
} }

@ -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,63 +29,48 @@
#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();
void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& encryptedBase64Token) UBApplication::showMessage(tr("Uploading Sankore File on Web."));
{ sendUbw();
mAuthenticationUuid = tokenUuid;
mAuthenticationBase64Token = encryptedBase64Token;
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();
dialog.author->setText(defaultAuthor);
if (dialog.exec() == QDialog::Accepted) void UBDocumentPublisher::buildUbwFile()
{ {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
UBApplication::showMessage(tr("Preparing document for upload..."), true);
mTitle = dialog.title->text();
mDescription = dialog.description->toPlainText();
mEMail = dialog.email->text();
mAuthor = dialog.author->text();
bool attachPDF = dialog.attachPDF->isChecked();
bool attachUBZ = dialog.attachUBZ->isChecked();
mPublishingServiceUrl = UBSettings::settings()->documentsPublishingUrl;
UBSettings::settings()->uniboardWebEMail->set(mEMail);
UBSettings::settings()->uniboardWebAuthor->set(mAuthor);
QDir d; QDir d;
d.mkpath(UBFileSystemUtils::defaultTempDirPath()); d.mkpath(UBFileSystemUtils::defaultTempDirPath());
@ -99,34 +85,21 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en
rasterizeScenes(); rasterizeScenes();
//rasterizePDF(); // not needed as we do not publish svg file anymore
//rasterizeSVGImages(); // not needed as we do not publish svg file anymore
upgradeDocumentForPublishing(); upgradeDocumentForPublishing();
if (attachPDF)
{
UBExportFullPDF pdfExporter; UBExportFullPDF pdfExporter;
pdfExporter.setVerbode(false); pdfExporter.setVerbode(false);
pdfExporter.persistsDocument(mSourceDocument, pdfExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf");
mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".pdf");
}
if (attachUBZ)
{
UBExportDocument ubzExporter; UBExportDocument ubzExporter;
ubzExporter.setVerbode(false); ubzExporter.setVerbode(false);
ubzExporter.persistsDocument(mSourceDocument, ubzExporter.persistsDocument(mSourceDocument, mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz");
mPublishingDocument->persistencePath() + "/" + UBStringUtils::toCanonicalUuid(publishingUuid) + ".ubz");
}
// remove all useless files // remove all useless files
for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) for (int pageIndex = 0; pageIndex < mPublishingDocument->pageCount(); pageIndex++) {
{ QString filename = mPublishingDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1);
QString filename = mPublishingDocument->persistencePath() +
UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1);
QFile::remove(filename); QFile::remove(filename);
} }
@ -136,16 +109,13 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory); UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::videoDirectory);
UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory); UBFileSystemUtils::deleteDir(mPublishingDocument->persistencePath() + "/" + UBPersistenceManager::audioDirectory);
QString tempZipFile = UBFileSystemUtils::defaultTempDirPath() mTmpZipFile = UBFileSystemUtils::defaultTempDirPath() + "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip";
+ "/" + UBStringUtils::toCanonicalUuid(QUuid::createUuid()) + ".zip";
//qDebug() << "compressing" << mPublishingDocument->persistencePath() << "in" << tempZipFile;
QuaZip zip(tempZipFile); QuaZip zip(mTmpZipFile);
zip.setFileNameCodec("UTF-8"); zip.setFileNameCodec("UTF-8");
if (!zip.open(QuaZip::mdCreate)) if (!zip.open(QuaZip::mdCreate))
{ {
qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << tempZipFile; qWarning() << "Export failed. Cause: zip.open(): " << zip.getZipError() << "," << mTmpZipFile;
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return; return;
} }
@ -156,7 +126,6 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en
{ {
qWarning("Export failed. compressDirInZip failed ..."); qWarning("Export failed. compressDirInZip failed ...");
zip.close(); zip.close();
//zip.remove();
UBApplication::showMessage(tr("Export failed.")); UBApplication::showMessage(tr("Export failed."));
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return; return;
@ -166,7 +135,6 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en
{ {
qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError());
zip.close(); zip.close();
//zip.remove();
UBApplication::showMessage(tr("Export failed.")); UBApplication::showMessage(tr("Export failed."));
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return; return;
@ -174,16 +142,6 @@ void UBDocumentPublisher::postDocument(const QUuid& tokenUuid, const QString& en
zip.close(); zip.close();
mPublishingUrl = QUrl(mPublishingServiceUrl + "/documents/publish/"
+ UBStringUtils::toCanonicalUuid(mSourceDocument->uuid()));
sendZipToUniboardWeb(tempZipFile, publishingUuid);
}
else
{
UBApplication::showMessage(tr("Export failed ..."));
QApplication::restoreOverrideCursor();
}
} }
else else
{ {
@ -192,53 +150,6 @@ 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()
{ {
@ -248,8 +159,7 @@ void UBDocumentPublisher::rasterizeScenes()
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);
@ -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))
@ -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,9 +338,7 @@ 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);
@ -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()
, "application/octet-stream");
mUploadRequest->setVerbose(true); void UBDocumentPublisher::init()
{
connect(mUploadRequest, SIGNAL(progress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64))); mCrlf=0x0d;
connect(mUploadRequest, SIGNAL(finished(bool, const QByteArray&)), this, SLOT(postZipUploadResponse(bool, const QByteArray&))); mCrlf+=0x0a;
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()); mpNetworkMgr = new QNetworkAccessManager(this);
mpCookieJar = new QNetworkCookieJar();
zipFile.remove(); connect(mpNetworkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
} }
void UBDocumentPublisher::onFinished(QNetworkReply *reply)
{
QByteArray response = reply->readAll();
void UBDocumentPublisher::uploadProgress(qint64 bytesSent, qint64 bytesTotal) if (!bCookieSet)
{ {
int percentage = (((qreal)bytesSent / (qreal)bytesTotal ) * 100); 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("; ");
if (bytesSent < bytesTotal) // Finally we create the cookies
UBApplication::showMessage(tr("Upload to Uniboard Web in progress %1 %").arg(percentage), true); 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 else
UBApplication::showMessage(tr("Sending document ..."), true); crntCookie = QNetworkCookie(qslCrntCookie.at(0).toAscii().constData());
cookiesList << crntCookie;
}
// Set the cookiejar : it set the cookies that will be sent with every packet.
qDebug() << reply->url().toString();
mpCookieJar->setCookiesFromUrl(cookiesList, reply->url());
mpNetworkMgr->setCookieJar(mpCookieJar);
bCookieSet = true;
}
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();
}
}
void UBDocumentPublisher::postZipUploadResponse(bool success, const QByteArray& payload) void UBDocumentPublisher::sendUbw()
{ {
if (success) if (QFile::exists(mTmpZipFile))
{ {
UBApplication::showMessage(tr("The document has been sent to %1").arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false); QFile f(mTmpZipFile);
} if (f.open(QIODevice::ReadOnly))
else
{ {
qWarning() << "error uploading document to Uniboard Web" << QString::fromUtf8(payload); QByteArray ba = f.readAll();
QString boundary,data, multipartHeader;
QByteArray datatoSend;
QString errorMessage = QString::fromUtf8(payload); boundary = "---WebKitFormBoundaryDKBTgA53MiyWrzLY";
multipartHeader = "multipart/form-data; boundary="+boundary;
if (errorMessage.length() == 0) data="--"+boundary+mCrlf;
UBApplication::showMessage(tr("Error while publishing document to %1") data+="Content-Disposition: form-data; name=\"file\"; filename=\""+ f.fileName() +"\""+mCrlf;
.arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false); data+="Content-Type: application/octet-stream"+mCrlf+mCrlf;
else datatoSend=data.toAscii(); // convert data string to byte array for request
UBApplication::showMessage(tr("Error while publishing document to %1 : (%2)") datatoSend += ba;
.arg(UBSettings::settings()->uniboardWebUrl->get().toString()) datatoSend += mCrlf.toAscii();
.arg(errorMessage), false); datatoSend += QString("--%0--%1").arg(boundary).arg(mCrlf).toAscii();
}
QApplication::restoreOverrideCursor(); 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");
deleteLater(); 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);
}
}
}
UBDocumentPublishingDialog::UBDocumentPublishingDialog(QWidget *parent) QString UBDocumentPublisher::getBase64Of(QString stringToEncode)
: QDialog(parent)
{ {
Ui::documentPublishingDialog::setupUi(this); return stringToEncode.toAscii().toBase64();
}
connect(dialogButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(dialogButtons, SIGNAL(rejected()), this, SLOT(reject()));
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,6 +10,7 @@
class UBDocumentProxy; class UBDocumentProxy;
class UBServerXMLHttpRequest; class UBServerXMLHttpRequest;
class UBGraphicsW3CWidgetItem; class UBGraphicsW3CWidgetItem;
class QWebView;
class UBDocumentPublisher : public UBAbstractPublisher class UBDocumentPublisher : public UBAbstractPublisher
{ {
@ -21,63 +22,43 @@ class UBDocumentPublisher : public UBAbstractPublisher
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 updateGoogleMapApiKey();
virtual void rasterizeScenes(); virtual void rasterizeScenes();
virtual void upgradeDocumentForPublishing(); virtual void upgradeDocumentForPublishing();
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber); virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber);
void sendZipToUniboardWeb(const QString& zipFile, const QUuid& publishingUuid);
private slots: private slots:
void postDocument(const QUuid& tokenUuid, const QString& encryptedBase64Token); void onFinished(QNetworkReply* reply);
void uploadProgress(qint64, qint64); void onLinkClicked(const QUrl& url);
void postZipUploadResponse(bool, const QByteArray&); void onLoadFinished(bool result);
private: private:
UBDocumentProxy *mSourceDocument; UBDocumentProxy *mSourceDocument;
UBDocumentProxy *mPublishingDocument; UBDocumentProxy *mPublishingDocument;
void init();
UBServerXMLHttpRequest* mUploadRequest; void sendUbw();
QString getBase64Of(QString stringToEncode);
QString mTitle;
QString mAuthor; QWebView* mpWebView;
QString mDescription; QHBoxLayout* mpLayout;
QString mEMail; QNetworkAccessManager* mpNetworkMgr;
bool mAttachPDF; QNetworkCookieJar* mpCookieJar;
bool mAttachUBZ; QString mUsername;
QString mPassword;
QUrl mPublishingUrl; QString mCrlf;
bool bCookieSet;
QString mPublishingServiceUrl;
QUuid mAuthenticationUuid; void buildUbwFile();
QString mAuthenticationBase64Token; QString mTmpZipFile;
}; };
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()));

@ -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,8 +90,7 @@ 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)
{ {
@ -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
} }
@ -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)

@ -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)
@ -33,8 +33,8 @@ UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent)
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
} }

@ -309,9 +309,9 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event)
UBKeyboardButton::UBKeyboardButton(UBKeyboardPalette* parent) UBKeyboardButton::UBKeyboardButton(UBKeyboardPalette* parent)
:QWidget(parent), :QWidget(parent),
keyboard(parent),
bFocused(false), bFocused(false),
bPressed(false), bPressed(false)
keyboard(parent)
{ {
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
} }

@ -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,19 +12,12 @@
#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 int UBGraphicsProtractor::sDrawTransparency = 192;
const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350); 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)
@ -34,46 +27,35 @@ UBGraphicsProtractor::UBGraphicsProtractor()
, mSpan(180) , mSpan(180)
, mStartAngle(0) , mStartAngle(0)
, mScaleFactor(1) , mScaleFactor(1)
, mCloseSvgItem(0)
, mResetSvgItem(0) , mResetSvgItem(0)
, mResizeSvgItem(0) , mResizeSvgItem(0)
, mRotateSvgItem(0)
, mMarkerSvgItem(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);
} }
@ -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);
@ -323,7 +305,7 @@ qreal UBGraphicsProtractor::antiScale() const
} }
QRectF UBGraphicsProtractor::resetButtonBounds () const QRectF UBGraphicsProtractor::resetButtonRect () const
{ {
qreal antiSc = antiScale(); qreal antiSc = antiScale();
@ -336,7 +318,7 @@ QRectF UBGraphicsProtractor::resetButtonBounds () const
} }
QRectF UBGraphicsProtractor::closeButtonBounds () const QRectF UBGraphicsProtractor::closeButtonRect () const
{ {
qreal antiSc = antiScale(); qreal antiSc = antiScale();
@ -352,7 +334,7 @@ QRectF UBGraphicsProtractor::closeButtonBounds () const
} }
QRectF UBGraphicsProtractor::resizeButtonBounds () const QRectF UBGraphicsProtractor::resizeButtonRect () const
{ {
qreal antiSc = antiScale(); qreal antiSc = antiScale();
@ -442,41 +424,41 @@ void UBGraphicsProtractor::paintButtons(QPainter *painter)
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);
@ -550,15 +532,15 @@ 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;
@ -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,6 +54,7 @@ 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);
@ -66,16 +63,15 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public
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 int sFillTransparency;
static const int sDrawTransparency;
static const QRectF sDefaultRect; static const QRectF sDefaultRect;
static const QColor sFillColor;
static const QColor sFillColorCenter; virtual void rotateAroundCenter(qreal angle);
static const QColor sDrawColor; virtual QPointF rotationCenter() const;
static const QColor sDarkBackgroundFillColor;
static const QColor sDarkBackgroundFillColorCenter; int sFillTransparency;
static const QColor sDarkBackgroundDrawColor; int sDrawTransparency;
}; };
#endif /* UBGRAPHICSPROTRACTOR_H_ */ #endif /* UBGRAPHICSPROTRACTOR_H_ */

@ -18,47 +18,44 @@
#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)
{
if (event->pos().x() > resizeButtonRect().left())
{
mResizing = true;
event->accept();
}
else if (rotateButtonRect().contains(event->pos()))
{ {
return scene()->isDarkBackground() ? sDarkBackgroundDrawColor : sLightBackgroundDrawColor; 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)
{
if (!mResizing && !mRotating)
{ {
return scene()->isDarkBackground() ? sDarkBackgroundMiddleFillColor : sLightBackgroundMiddleFillColor; 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));
} }
QColor UBGraphicsRuler::edgeFillColor() const event->accept();
}
}
void UBGraphicsRuler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
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()))
{ {
return scene()->isDarkBackground() ? sDarkBackgroundEdgeFillColor : sLightBackgroundEdgeFillColor; hide();
emit hidden();
event->accept();
}
else
{
QGraphicsItem::mouseReleaseEvent(event);
} }
QFont UBGraphicsRuler::font() const if (scene())
scene()->setModified(true);
}
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,11 +39,8 @@ 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);
@ -56,58 +53,37 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu
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;
// Members
bool mResizing;
bool mRotating;
bool mShowButtons;
QGraphicsSvgItem* mCloseSvgItem;
QGraphicsSvgItem* mRotateSvgItem; QGraphicsSvgItem* mRotateSvgItem;
QGraphicsSvgItem* mResizeSvgItem; QGraphicsSvgItem* mResizeSvgItem;
void updateResizeCursor();
QCursor resizeCursor() const{return mResizeCursor;}
virtual QPointF rotationCenter() const;
virtual QRectF resizeButtonRect() const;
virtual QRectF closeButtonRect() const;
virtual QRectF rotateButtonRect() const;
virtual UBGraphicsScene* scene() const;
QCursor mResizeCursor; QCursor mResizeCursor;
qreal mAntiScaleRatio;
QPointF startDrawPosition; 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