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

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

@ -2,8 +2,23 @@
make clean
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
@ -25,7 +40,36 @@ chmod +x build/linux/release/product/run.sh
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
mkdir -p install/linux
@ -35,4 +79,5 @@ cd build/linux/release
# "Removing .svn directories ..."
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
LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
./Sankore\ 3.1
env LD_LIBRARY_PATH=$PWD/qtlib:$LD_LIBRARY_PATH ./Sankore\ 3.1

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

@ -99,5 +99,5 @@ QString UBExportDocument::exportExtention()
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)
{
UBApplication::showMessage(tr("Importing Uniboard printer file ..."));
UBApplication::showMessage(tr("Importing Sankore printer file ..."));
UBDocumentProxy *document = 0;
QString pdfFilename = pdfFileName(pFile);
@ -159,7 +159,7 @@ UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QS
if (!document)
{
UBApplication::showMessage(tr("Error while importing Uniboard printer file."));
UBApplication::showMessage(tr("Error while importing Sankore printer file."));
}
cleanUp(pFile, pdfFilename, emfFileNames(pFile));
@ -170,7 +170,7 @@ UBDocumentProxy* UBImportVirtualPrinter::importFile(const QFile& pFile, const QS
bool UBImportVirtualPrinter::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile)
{
UBApplication::showMessage(tr("Importing Uniboard printer file ..."));
UBApplication::showMessage(tr("Importing Sankore printer file ..."));
bool result = false;
QString pdfFilename = pdfFileName(pFile);
@ -183,7 +183,7 @@ bool UBImportVirtualPrinter::addFileToDocument(UBDocumentProxy* pDocument, const
if (!result)
{
UBApplication::showMessage(tr("Error while importing Uniboard printer file."));
UBApplication::showMessage(tr("Error while importing Sankore printer file."));
}
cleanUp(pFile, pdfFilename, emfFileNames(pFile));

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

@ -26,6 +26,7 @@
#include "tools/UBGraphicsCompass.h"
#include "tools/UBGraphicsProtractor.h"
#include "tools/UBGraphicsCurtainItem.h"
#include "tools/UBGraphicsTriangle.h"
#include "document/UBDocumentProxy.h"
@ -644,6 +645,16 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(protractor);
scene->registerTool(protractor);
}
}
else if (mXmlReader.name() == "protractor")
{
UBGraphicsTriangle *triangle = triangleFromSvg();
if (triangle)
{
scene->addItem(triangle);
scene->registerTool(triangle);
}
}
else if (mXmlReader.name() == "foreignObject")
{
@ -770,7 +781,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
if (mXmlReader.hasError())
{
qWarning() << "error parsing uniboard file " << mXmlReader.errorString();
qWarning() << "error parsing Sankore file " << mXmlReader.errorString();
}
if (scene)
@ -2556,7 +2567,31 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg()
return protractor;
}
UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg()
{
UBGraphicsTriangle* triangle = new UBGraphicsTriangle();
triangle->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetTriangle);
triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
graphicsItemFromSvg(triangle);
QStringRef 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)
{

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

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

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

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

@ -956,7 +956,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
}
else
{
UBApplication::showMessage(tr("Flash is not supported on Uniboard Linux"));
UBApplication::showMessage(tr("Flash is not supported on Sankore Linux"));
}
}
else if (mimeType.startsWith("application/pdf"))

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

@ -27,9 +27,10 @@ UBDrawingController* UBDrawingController::drawingController()
UBDrawingController::UBDrawingController(QObject * parent)
: QObject(parent)
, mActiveRuler(NULL)
, mStylusTool((UBStylusTool::Enum)-1)
, mLatestDrawingTool((UBStylusTool::Enum)-1)
, mActiveRuler(NULL)
{
connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged()));
@ -171,7 +172,7 @@ void UBDrawingController::setLineWidthIndex(int index)
{
UBSettings::settings()->setPenWidthIndex(index);
if(stylusTool() != UBStylusTool::Line
if(stylusTool() != UBStylusTool::Line
&& stylusTool() != UBStylusTool::Selector)
{
setStylusTool(UBStylusTool::Pen);

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

@ -724,7 +724,7 @@ UBLibElement* UBLibElement::trashElement()
if (trashElement)
return trashElement;
trashElement = new UBLibElement(eUBLibElementType_Folder, UBSettings::trashLibraryPaletteDirPath(), QObject::tr("Trash", "Pictures category element"));
trashElement = new UBLibElement(eUBLibElementType_Folder, QUrl::fromLocalFile(UBSettings::trashLibraryPaletteDirPath()), QObject::tr("Trash", "Pictures category element"));
QImage *categoryImage = new QImage(":images/libpalette/TrashCategory.svg");
trashElement->setThumbnail(categoryImage);
trashElement->setMoveable(false);

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

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

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

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

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

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

@ -1000,7 +1000,7 @@ void UBPersistenceManager::checkIfDocumentRepositoryExists()
QMessageBox::question(
QApplication::activeWindow(),
tr("Document Repository Loss"),
tr("Uniboard has lost access to the document repository '%1'. Unfortunately the application must shut down to avoid data corruption. Latest changes may be lost as well.").arg(humanPath),
tr("Sankore has lost access to the document repository '%1'. Unfortunately the application must shut down to avoid data corruption. Latest changes may be lost as well.").arg(humanPath),
QMessageBox::Yes);
UBApplication::quit();

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

@ -54,9 +54,14 @@ void ub_message_output(QtMsgType type, const char *msg) {
int main(int argc, char *argv[])
{
// Uncomment next section to have memory leaks information
// tracing in VC++ debug mode under Windows
/*
#if defined(_MSC_VER) && defined(_DEBUG)
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
*/
Q_INIT_RESOURCE(sankore);

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

@ -1446,7 +1446,7 @@ bool UBDocumentController::isOKToOpenDocument(UBDocumentProxy* proxy)
else
{
if (QMessageBox::question( 0, tr("Open Document"),
tr("The document '%1' has been generated with a newer version of Uniboard (%2). By opening it, you may lose some information. Do you want to proceed?")
tr("The document '%1' has been generated with a newer version of Sankore (%2). By opening it, you may lose some information. Do you want to proceed?")
.arg(proxy->metaData(UBSettings::documentName).toString())
.arg(docVersion),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)

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

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

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

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

@ -56,6 +56,8 @@ QString UBPlatformUtils::preferredLanguage()
void UBPlatformUtils::runInstaller(const QString &installerFilePath)
{
// TODO UB 4.x - auto update & installer are deactivated on Linux
Q_UNUSED(installerFilePath);
}
void UBPlatformUtils::bringPreviousProcessToFront()
@ -77,6 +79,8 @@ QString UBPlatformUtils::computerName()
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)
{
// NOOP
Q_UNUSED(desktop);
}
const KEYBT ENGLISH_LOCALE[] = {

@ -46,8 +46,8 @@ void UBPlatformUtils::init()
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *currentPath = [[NSBundle mainBundle] pathForResource:@"Save PDF to Uniboard" ofType:@"workflow"];
NSString *installedPath = [[[@"~/Library/PDF Services" stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Save PDF to Uniboard"] stringByAppendingPathExtension:@"workflow"];
NSString *currentPath = [[NSBundle mainBundle] pathForResource:@"Save PDF to Sankore" ofType:@"workflow"];
NSString *installedPath = [[[@"~/Library/PDF Services" stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Save PDF to Sankore"] stringByAppendingPathExtension:@"workflow"];
NSString *currentVersion = bundleShortVersion([NSBundle bundleWithPath:currentPath]);
NSString *installedVersion = bundleShortVersion([NSBundle bundleWithPath:installedPath]);
@ -59,7 +59,7 @@ void UBPlatformUtils::init()
BOOL copyOK = [fileManager copyPath:currentPath toPath:installedPath handler:nil];
if (!copyOK)
{
qWarning("Could not install the 'Save PDF to Uniboard' workflow");
qWarning("Could not install the 'Save PDF to Sankore' workflow");
}
}
@ -364,25 +364,25 @@ KEYBT* createKeyBt(const UCKeyboardLayout* keyLayout, int vkk)
void UBPlatformUtils::initializeKeyboardLayouts()
{
CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceIsEnableCapable, kTISPropertyInputSourceIsSelectCapable };
const void* values[] = { kTISCategoryKeyboardInputSource, kCFBooleanTrue, kCFBooleanTrue };
CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 3, NULL, NULL);
CFArrayRef kbds = TISCreateInputSourceList(dict, false);
int count = CFArrayGetCount(kbds);
CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceIsEnableCapable, kTISPropertyInputSourceIsSelectCapable };
const void* values[] = { kTISCategoryKeyboardInputSource, kCFBooleanTrue, kCFBooleanTrue };
CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 3, NULL, NULL);
CFArrayRef kbds = TISCreateInputSourceList(dict, false);
int count = CFArrayGetCount(kbds);
QList<UBKeyboardLocale*> result;
for(int i=0; i<count; i++)
{
TISInputSourceRef keyLayoutRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);
TISInputSourceRef keyLayoutRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);
if (keyLayoutRef==NULL)
continue;
CFDataRef ref = (CFDataRef) TISGetInputSourceProperty(keyLayoutRef,
kTISPropertyUnicodeKeyLayoutData);
kTISPropertyUnicodeKeyLayoutData);
if (ref==NULL)
continue;
const UCKeyboardLayout* keyLayout = (const UCKeyboardLayout*) CFDataGetBytePtr(ref);
const UCKeyboardLayout* keyLayout = (const UCKeyboardLayout*) CFDataGetBytePtr(ref);
if (keyLayoutRef==NULL)
continue;
@ -438,12 +438,12 @@ void UBPlatformUtils::initializeKeyboardLayouts()
keybt[44] = createKeyBt(keyLayout, 43);
keybt[45] = createKeyBt(keyLayout, 47);
keybt[46] = createKeyBt(keyLayout, 44);
CFStringRef sr = (CFStringRef) TISGetInputSourceProperty(keyLayoutRef, kTISPropertyInputSourceID);
CFStringRef sr = (CFStringRef) TISGetInputSourceProperty(keyLayoutRef, kTISPropertyInputSourceID);
QString ID = QStringFromStringRef(sr);
sr = (CFStringRef) TISGetInputSourceProperty(keyLayoutRef, kTISPropertyLocalizedName);
sr = (CFStringRef) TISGetInputSourceProperty(keyLayoutRef, kTISPropertyLocalizedName);
QString fullName = QStringFromStringRef(sr);
CFArrayRef langs = (CFArrayRef) TISGetInputSourceProperty(keyLayoutRef,
@ -455,13 +455,13 @@ void UBPlatformUtils::initializeKeyboardLayouts()
CFStringRef langRef = (CFStringRef)CFArrayGetValueAtIndex(langs, 0);
name = QStringFromStringRef(langRef);
}
//IconRef iconRef = (IconRef)TISGetInputSourceProperty(kTISPropertyIconRef,
// kTISPropertyInputSourceLanguages);
result.append(new UBKeyboardLocale(fullName, name, ID, NULL, keybt));
}
if (result.size()==0)
{
nKeyboardLayouts = 0;

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

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

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

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

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

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

@ -14,6 +14,7 @@ UBMainWindow::UBMainWindow(QWidget *parent, Qt::WindowFlags flags)
, mBoardWidget(0)
, mWebWidget(0)
, mDocumentsWidget(0)
, mSankoreWebDocumentWidget(0)
{
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)
{
QMainWindow::keyPressEvent(event);

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

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

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

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

@ -1,11 +1,114 @@
#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"
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()
: 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()
{
}
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,19 +3,67 @@
#include <QtGui>
class UBGraphicsScene;
class QGraphicsSvgItem;
class UBAbstractDrawRuler : public QObject
{
Q_OBJECT;
Q_OBJECT
public:
UBAbstractDrawRuler();
~UBAbstractDrawRuler();
public:
UBAbstractDrawRuler();
~UBAbstractDrawRuler();
virtual void StartLine(const QPointF& position, qreal width) = 0;
virtual void DrawLine(const QPointF& position, qreal width) = 0;
virtual void EndLine() = 0;
void create(QGraphicsItem& item);
virtual void StartLine(const QPointF& position, qreal width);
virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine();
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;
};
#endif
#endif

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

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

@ -39,75 +39,51 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu
virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine();
signals:
void hidden();
protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
// Events
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
private:
bool mResizing;
bool mRotating;
// Helpers
void fillBackground(QPainter *painter);
void paintGraduations(QPainter *painter);
void paintRotationCenter(QPainter *painter);
void rotateAroundTopLeftOrigin(qreal angle);
void updateResizeCursor();
QPointF topLeftOrigin() const;
QCursor moveCursor() const;
QCursor resizeCursor() const;
QCursor rotateCursor() const;
QCursor closeCursor() const;
QCursor drawRulerLineCursor() const;
QRectF resizeButtonRect() const;
QRectF closeButtonRect() const;
QRectF rotateButtonRect() const;
UBGraphicsScene* scene() const;
QColor drawColor() const;
QColor middleFillColor() const;
QColor edgeFillColor() const;
QFont font() const;
void fillBackground(QPainter *painter);
void paintGraduations(QPainter *painter);
void paintRotationCenter(QPainter *painter);
virtual void rotateAroundCenter(qreal angle);
int drawLineDirection;
QGraphicsSvgItem* mRotateSvgItem;
QGraphicsSvgItem* mResizeSvgItem;
// Members
bool mResizing;
bool mRotating;
bool mShowButtons;
QGraphicsSvgItem* mCloseSvgItem;
QGraphicsSvgItem* mRotateSvgItem;
QGraphicsSvgItem* mResizeSvgItem;
QCursor mResizeCursor;
qreal mAntiScaleRatio;
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;
QPointF startDrawPosition;
QCursor mResizeCursor;
int drawLineDirection;
// Constants
static const QRect sDefaultRect;
static const int sLeftEdgeMargin = 10;
static const int sMinLength = 150;
static const int sDegreeToQtAngleUnit = 16;
static const int sRotationRadius = 15;
static const int sPixelsPerMillimeter = 5;
static const int sFillTransparency = 127;
static const int sDrawTransparency = 192;
static const int sRoundingRadius = sLeftEdgeMargin / 2;
static const QColor sLightBackgroundEdgeFillColor;
static const QColor sLightBackgroundMiddleFillColor;
static const QColor sLightBackgroundDrawColor;
static const QColor sDarkBackgroundEdgeFillColor;
static const QColor sDarkBackgroundMiddleFillColor;
static const QColor sDarkBackgroundDrawColor;
static const int sMinLength = 150;
};
#endif /* UBGRAPHICSRULER_H_ */

@ -1,10 +1,555 @@
#include <QGraphicsPolygonItem>
#include <QPolygonF>
#include "tools/UBGraphicsTriangle.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "board/UBDrawingController.h"
#include "domain/UBGraphicsScene.h"
#include "core/memcheck.h"
const QRect UBGraphicsTriangle::sDefaultRect = QRect(0, 0, 800, 400);
const UBGraphicsTriangle::UBGraphicsTriangleOrientation UBGraphicsTriangle::sDefaultOrientation =
UBGraphicsTriangle::BottomLeft;
UBGraphicsTriangle::UBGraphicsTriangle()
: QGraphicsPolygonItem()
, 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()
{}
{
}
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 "domain/UBItem.h"
#include "tools/UBAbstractDrawRuler.h"
class UBGraphicsScene;
class UBItem;
class UBGraphicsTriangle : public QObject, public QGraphicsPolygonItem, public UBItem
class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonItem, public UBItem
{
Q_OBJECT;
public:
UBGraphicsTriangle();
virtual ~UBGraphicsTriangle();
enum { Type = UBGraphicsItemType::TriangleItemType };
virtual int type() const
{
return Type;
}
virtual UBItem* deepCopy(void) const;
enum UBGraphicsTriangleOrientation
{
BottomLeft = 0,
BottomRight,
TopLeft,
TopRight
};
static UBGraphicsTriangleOrientation orientationFromStr(QStringRef& str)
{
if (str == "BottomLeft") return BottomLeft;
if (str == "BottomRight") return BottomRight;
if (str == "TopLeft") return TopLeft;
if (str == "TopRight") return TopRight;
return sDefaultOrientation;
}
void setRect(const QRectF &rect, UBGraphicsTriangleOrientation orientation)
{
setRect(rect.x(), rect.y(), rect.width(), rect.height(), orientation);
}
void setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation);
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_ */

@ -151,7 +151,7 @@ void WBWebPage::handleUnsupportedContent(QNetworkReply *reply)
if (isPDF)
{
QMessageBox messageBox(mainWindow());
messageBox.setText(tr("Download PDF Document: would you prefer to download the PDF file or add it to the current Uniboard document?"));
messageBox.setText(tr("Download PDF Document: would you prefer to download the PDF file or add it to the current Sankore document?"));
messageBox.addButton(tr("Download"), QMessageBox::AcceptRole);
QAbstractButton *addButton =

Loading…
Cancel
Save