User-resizable background grid:

- The background selection palette now includes a slider to change the
size of the background grid. Default min/max values are 16 and 64px,
defined in UBSettings. Grid resizes dynamically as the slider is moved.
- Measuring tools' (ruler, triangle) markers follow grid size: 1 square
of the background grid corresponds to 1cm
- Grid size can be different for each page of a document
- Grid size is saved in the .svg
- Documents with a background grid but no specified grid size follow the
default size defined in UBSettings.

Previously, grid size was calculated based on DPI, which can vary from
one OS, computer or display to the next. This new setting allows
documents to be migrated from one machine to another with no unexpected
changes in grid size happening. It also makes it easy to correct any
problems importing old documents (whose grid size might be smaller or
larger than expected when imported on a new version of OpenBoard).
preferencesAboutTextFull
Craig Watson 8 years ago
parent 9b7993c59e
commit 081dbee1ed
  1. 19
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 4
      src/board/UBBoardController.cpp
  3. 11
      src/board/UBBoardPaletteManager.cpp
  4. 3
      src/board/UBBoardPaletteManager.h
  5. 8
      src/board/UBBoardView.cpp
  6. 4
      src/core/UBSettings.cpp
  7. 4
      src/core/UBSettings.h
  8. 23
      src/domain/UBGraphicsScene.cpp
  9. 8
      src/domain/UBGraphicsScene.h
  10. 12
      src/gui/UBActionPalette.h
  11. 153
      src/gui/UBBackgroundPalette.cpp
  12. 46
      src/gui/UBBackgroundPalette.h
  13. 6
      src/gui/gui.pri
  14. 5
      src/tools/UBAbstractDrawRuler.cpp
  15. 2
      src/tools/UBAbstractDrawRuler.h
  16. 8
      src/tools/UBGraphicsCompass.cpp
  17. 1
      src/tools/UBGraphicsCompass.h
  18. 57
      src/tools/UBGraphicsRuler.cpp
  19. 35
      src/tools/UBGraphicsTriangle.cpp

@ -453,11 +453,22 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx
QStringRef ubCrossedBackground = mXmlReader.attributes().value(mNamespaceUri, "crossed-background"); QStringRef ubCrossedBackground = mXmlReader.attributes().value(mNamespaceUri, "crossed-background");
if (!ubDarkBackground.isNull()) if (!ubCrossedBackground.isNull())
crossedBackground = (ubCrossedBackground.toString() == xmlTrue); crossedBackground = (ubCrossedBackground.toString() == xmlTrue);
mScene->setBackground(darkBackground, crossedBackground); mScene->setBackground(darkBackground, crossedBackground);
if (crossedBackground) {
QStringRef ubGridSize = mXmlReader.attributes().value(mNamespaceUri, "grid-size");
if (!ubGridSize.isNull()) {
int gridSize = ubGridSize.toInt();
UBSettings::settings()->crossSize = gridSize;
mScene->setBackgroundGridSize(gridSize);
}
}
QStringRef pageNominalSize = mXmlReader.attributes().value(mNamespaceUri, "nominal-size"); QStringRef pageNominalSize = mXmlReader.attributes().value(mNamespaceUri, "nominal-size");
if (!pageNominalSize.isNull()) if (!pageNominalSize.isNull())
{ {
@ -1068,6 +1079,12 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement(UBDocumentProxy* pro
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "dark-background", mScene->isDarkBackground() ? xmlTrue : xmlFalse); mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "dark-background", mScene->isDarkBackground() ? xmlTrue : xmlFalse);
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "crossed-background", mScene->isCrossedBackground() ? xmlTrue : xmlFalse); mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "crossed-background", mScene->isCrossedBackground() ? xmlTrue : xmlFalse);
if (mScene->isCrossedBackground()) {
int gridSize = mScene->backgroundGridSize();
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "grid-size", QString::number(gridSize));
}
QDesktopWidget* desktop = UBApplication::desktop(); QDesktopWidget* desktop = UBApplication::desktop();
if (proxy->pageDpi() == 0) if (proxy->pageDpi() == 0)

@ -122,10 +122,6 @@ UBBoardController::UBBoardController(UBMainWindow* mainWindow)
mMarkerColorOnDarkBackground = UBSettings::settings()->markerColors(true).at(markerColorIndex); mMarkerColorOnDarkBackground = UBSettings::settings()->markerColors(true).at(markerColorIndex);
mMarkerColorOnLightBackground = UBSettings::settings()->markerColors(false).at(markerColorIndex); mMarkerColorOnLightBackground = UBSettings::settings()->markerColors(false).at(markerColorIndex);
QDesktopWidget* desktop = UBApplication::desktop();
int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
int sPixelsPerMillimeter = qRound(dpiCommon / UBGeometryUtils::inchSize);
UBSettings::settings()->crossSize = 10*sPixelsPerMillimeter;
} }

@ -45,6 +45,7 @@
#include "gui/UBZoomPalette.h" #include "gui/UBZoomPalette.h"
#include "gui/UBWebToolsPalette.h" #include "gui/UBWebToolsPalette.h"
#include "gui/UBActionPalette.h" #include "gui/UBActionPalette.h"
#include "gui/UBBackgroundPalette.h"
#include "gui/UBFavoriteToolPalette.h" #include "gui/UBFavoriteToolPalette.h"
#include "gui/UBStartupHintsPalette.h" #include "gui/UBStartupHintsPalette.h"
@ -253,11 +254,11 @@ void UBBoardPaletteManager::setupPalettes()
backgroundsActions << UBApplication::mainWindow->actionPlainDarkBackground; backgroundsActions << UBApplication::mainWindow->actionPlainDarkBackground;
backgroundsActions << UBApplication::mainWindow->actionCrossedDarkBackground; backgroundsActions << UBApplication::mainWindow->actionCrossedDarkBackground;
mBackgroundsPalette = new UBActionPalette(backgroundsActions, Qt::Horizontal , mContainer); mBackgroundsPalette = new UBBackgroundPalette(backgroundsActions, mContainer);
mBackgroundsPalette->setButtonIconSize(QSize(128, 128)); mBackgroundsPalette->setButtonIconSize(QSize(128, 128));
mBackgroundsPalette->groupActions(); mBackgroundsPalette->groupActions();
mBackgroundsPalette->setClosable(true); mBackgroundsPalette->setClosable(true);
mBackgroundsPalette->setAutoClose(true); mBackgroundsPalette->setAutoClose(false);
mBackgroundsPalette->adjustSizeAndPosition(); mBackgroundsPalette->adjustSizeAndPosition();
mBackgroundsPalette->hide(); mBackgroundsPalette->hide();
@ -532,7 +533,7 @@ void UBBoardPaletteManager::changeBackground()
else else
UBApplication::boardController->changeBackground(false, false); UBApplication::boardController->changeBackground(false, false);
UBApplication::mainWindow->actionBackgrounds->setChecked(false); mBackgroundsPalette->backgroundChanged();
} }
@ -552,8 +553,10 @@ void UBBoardPaletteManager::activeSceneChanged()
if (mZoomPalette) if (mZoomPalette)
connect(mZoomPalette, SIGNAL(mouseEntered()), activeScene, SLOT(hideTool())); connect(mZoomPalette, SIGNAL(mouseEntered()), activeScene, SLOT(hideTool()));
if (mBackgroundsPalette) if (mBackgroundsPalette) {
connect(mBackgroundsPalette, SIGNAL(mouseEntered()), activeScene, SLOT(hideTool())); connect(mBackgroundsPalette, SIGNAL(mouseEntered()), activeScene, SLOT(hideTool()));
mBackgroundsPalette->refresh();
}
} }

@ -48,6 +48,7 @@ class UBClockPalette;
class UBPageNumberPalette; class UBPageNumberPalette;
class UBZoomPalette; class UBZoomPalette;
class UBActionPalette; class UBActionPalette;
class UBBackgroundPalette;
class UBBoardController; class UBBoardController;
class UBServerXMLHttpRequest; class UBServerXMLHttpRequest;
class UBKeyboardPalette; class UBKeyboardPalette;
@ -113,7 +114,7 @@ class UBBoardPaletteManager : public QObject
/** The right dock palette */ /** The right dock palette */
UBRightPalette* mRightPalette; UBRightPalette* mRightPalette;
UBActionPalette *mBackgroundsPalette; UBBackgroundPalette *mBackgroundsPalette;
UBActionPalette *mToolsPalette; UBActionPalette *mToolsPalette;
UBActionPalette* mAddItemPalette; UBActionPalette* mAddItemPalette;
UBActionPalette* mErasePalette; UBActionPalette* mErasePalette;

@ -1609,16 +1609,16 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
if (scene () && scene ()->isCrossedBackground ()) if (scene () && scene ()->isCrossedBackground ())
{ {
qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize; qreal firstY = ((int) (rect.y () / scene()->backgroundGridSize())) * scene()->backgroundGridSize();
for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize) for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += scene()->backgroundGridSize())
{ {
painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
} }
qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize; qreal firstX = ((int) (rect.x () / scene()->backgroundGridSize())) * scene()->backgroundGridSize();
for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize) for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += scene()->backgroundGridSize())
{ {
painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ());
} }

@ -46,7 +46,9 @@
QPointer<UBSettings> UBSettings::sSingleton = 0; QPointer<UBSettings> UBSettings::sSingleton = 0;
int UBSettings::pointerDiameter = 40; int UBSettings::pointerDiameter = 40;
int UBSettings::crossSize = 32; int UBSettings::crossSize = 24;
int UBSettings::minCrossSize = 12;
int UBSettings::maxCrossSize = 64;
int UBSettings::colorPaletteSize = 5; int UBSettings::colorPaletteSize = 5;
int UBSettings::objectFrameWidth = 20; int UBSettings::objectFrameWidth = 20;
int UBSettings::boardMargin = 10; int UBSettings::boardMargin = 10;

@ -182,7 +182,11 @@ class UBSettings : public QObject
static QColor documentSizeMarkColorDarkBackground; static QColor documentSizeMarkColorDarkBackground;
static QColor documentSizeMarkColorLightBackground; static QColor documentSizeMarkColorLightBackground;
// Background grid
static int crossSize; static int crossSize;
static int minCrossSize;
static int maxCrossSize;
static int colorPaletteSize; static int colorPaletteSize;
static int objectFrameWidth; static int objectFrameWidth;

@ -353,6 +353,8 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
UBApplication::applicationController->initialVScroll())); UBApplication::applicationController->initialVScroll()));
} }
mBackgroundGridSize = UBSettings::settings()->crossSize;
// Just for debug. Do not delete please // Just for debug. Do not delete please
// connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); // connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
connect(UBApplication::undoStack.data(), SIGNAL(indexChanged(int)), this, SLOT(updateSelectionFrameWrapper(int))); connect(UBApplication::undoStack.data(), SIGNAL(indexChanged(int)), this, SLOT(updateSelectionFrameWrapper(int)));
@ -981,6 +983,18 @@ void UBGraphicsScene::setBackgroundZoomFactor(qreal zoom)
mZoomFactor = zoom; mZoomFactor = zoom;
} }
void UBGraphicsScene::setBackgroundGridSize(int pSize)
{
if (pSize > 0) {
mBackgroundGridSize = pSize;
setModified(true);
foreach(QGraphicsView* view, views())
view->resetCachedContent();
}
}
void UBGraphicsScene::setDrawingMode(bool bModeDesktop) void UBGraphicsScene::setDrawingMode(bool bModeDesktop)
{ {
mIsDesktopMode = bModeDesktop; mIsDesktopMode = bModeDesktop;
@ -1158,6 +1172,7 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const
UBGraphicsScene* copy = new UBGraphicsScene(this->document(), this->mUndoRedoStackEnabled); UBGraphicsScene* copy = new UBGraphicsScene(this->document(), this->mUndoRedoStackEnabled);
copy->setBackground(this->isDarkBackground(), this->isCrossedBackground()); copy->setBackground(this->isDarkBackground(), this->isCrossedBackground());
copy->setBackgroundGridSize(mBackgroundGridSize);
copy->setSceneRect(this->sceneRect()); copy->setSceneRect(this->sceneRect());
if (this->mNominalSize.isValid()) if (this->mNominalSize.isValid())
@ -2404,16 +2419,16 @@ void UBGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
if (isCrossedBackground()) if (isCrossedBackground())
{ {
qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize; qreal firstY = ((int) (rect.y () / backgroundGridSize())) * backgroundGridSize();
for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize) for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += backgroundGridSize())
{ {
painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
} }
qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize; qreal firstX = ((int) (rect.x () / backgroundGridSize())) * backgroundGridSize();
for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize) for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += backgroundGridSize())
{ {
painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ());
} }

@ -220,6 +220,11 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
return mCrossedBackground; return mCrossedBackground;
} }
int backgroundGridSize() const
{
return mBackgroundGridSize;
}
bool hasBackground() bool hasBackground()
{ {
return (mBackgroundObject != 0); return (mBackgroundObject != 0);
@ -331,6 +336,7 @@ public slots:
void setBackground(bool pIsDark, bool pIsCrossed); void setBackground(bool pIsDark, bool pIsCrossed);
void setBackgroundZoomFactor(qreal zoom); void setBackgroundZoomFactor(qreal zoom);
void setBackgroundGridSize(int pSize);
void setDrawingMode(bool bModeDesktop); void setDrawingMode(bool bModeDesktop);
void deselectAllItems(); void deselectAllItems();
@ -404,6 +410,8 @@ public slots:
bool mDarkBackground; bool mDarkBackground;
bool mCrossedBackground; bool mCrossedBackground;
int mBackgroundGridSize;
bool mIsDesktopMode; bool mIsDesktopMode;
qreal mZoomFactor; qreal mZoomFactor;

@ -55,9 +55,9 @@ class UBActionPalette : public UBFloatingPalette
void setToolButtonStyle(Qt::ToolButtonStyle); void setToolButtonStyle(Qt::ToolButtonStyle);
QList<QAction*> actions(); QList<QAction*> actions();
void setActions(QList<QAction*> actions); virtual void setActions(QList<QAction*> actions);
void groupActions(); void groupActions();
void addAction(QAction* action); virtual void addAction(QAction* action);
void setClosable(bool closable); void setClosable(bool closable);
void setAutoClose(bool autoClose) void setAutoClose(bool autoClose)
@ -72,10 +72,10 @@ class UBActionPalette : public UBFloatingPalette
bool m_customCloseProcessing; bool m_customCloseProcessing;
virtual int border(); virtual int border();
void clearLayout(); virtual void clearLayout();
QSize buttonSize(); QSize buttonSize();
UBActionPaletteButton* getButtonFromAction(QAction* action); virtual UBActionPaletteButton* getButtonFromAction(QAction* action);
public slots: public slots:
void close(); void close();
@ -91,7 +91,7 @@ class UBActionPalette : public UBFloatingPalette
virtual void mouseReleaseEvent(QMouseEvent * event); virtual void mouseReleaseEvent(QMouseEvent * event);
virtual void init(Qt::Orientation orientation); virtual void init(Qt::Orientation orientation);
void updateLayout(); virtual void updateLayout();
QList<UBActionPaletteButton*> mButtons; QList<UBActionPaletteButton*> mButtons;
QButtonGroup* mButtonGroup; QButtonGroup* mButtonGroup;
@ -105,7 +105,7 @@ class UBActionPalette : public UBFloatingPalette
QPoint mMousePos; QPoint mMousePos;
UBActionPaletteButton *createPaletteButton(QAction* action, QWidget *parent); UBActionPaletteButton *createPaletteButton(QAction* action, QWidget *parent);
private slots: protected slots:
void buttonClicked(); void buttonClicked();
void actionChanged(); void actionChanged();
}; };

@ -0,0 +1,153 @@
#include "UBBackgroundPalette.h"
UBBackgroundPalette::UBBackgroundPalette(QList<QAction*> actions, QWidget * parent)
: UBActionPalette(parent)
{
init();
setActions(actions);
}
UBBackgroundPalette::UBBackgroundPalette(QWidget * parent)
: UBActionPalette(parent)
{
init();
}
void UBBackgroundPalette::init()
{
UBActionPalette::clearLayout();
delete layout();
m_customCloseProcessing = false;
mButtonSize = QSize(32, 32);
mIsClosable = false;
mAutoClose = false;
mButtonGroup = 0;
mToolButtonStyle = Qt::ToolButtonIconOnly;
mButtons.clear();
mVLayout = new QVBoxLayout(this);
mTopLayout = new QHBoxLayout();
mBottomLayout = new QHBoxLayout();
mVLayout->addLayout(mTopLayout);
mVLayout->addLayout(mBottomLayout);
mSlider = new QSlider(Qt::Horizontal);
mSlider->setMinimum(UBSettings::settings()->minCrossSize);
mSlider->setMaximum(UBSettings::settings()->maxCrossSize);
mSlider->setSingleStep(2);
mSlider->setTracking(true); // valueChanged() is emitted during movement and not just upon releasing the slider
mSliderLabel = new QLabel(tr("Grid size"));
mBottomLayout->addSpacing(16);
mBottomLayout->addWidget(mSliderLabel);
mBottomLayout->addWidget(mSlider);
mBottomLayout->addSpacing(16);
updateLayout();
}
void UBBackgroundPalette::addAction(QAction* action)
{
UBActionPaletteButton* button = createPaletteButton(action, this);
mTopLayout->addWidget(button);
mActions << action;
}
void UBBackgroundPalette::setActions(QList<QAction*> actions)
{
mMapActionToButton.clear();
foreach(QAction* action, actions)
{
addAction(action);
}
actionChanged();
}
void UBBackgroundPalette::updateLayout()
{
if (mToolButtonStyle == Qt::ToolButtonIconOnly) {
mVLayout->setContentsMargins (sLayoutContentMargin / 2 + border(), sLayoutContentMargin / 2 + border()
, sLayoutContentMargin / 2 + border(), sLayoutContentMargin / 2 + border());
}
else
{
mVLayout->setContentsMargins (sLayoutContentMargin + border(), sLayoutContentMargin + border()
, sLayoutContentMargin + border(), sLayoutContentMargin + border());
}
update();
}
void UBBackgroundPalette::clearLayout()
{
while(!mTopLayout->isEmpty()) {
QLayoutItem* pItem = mTopLayout->itemAt(0);
QWidget* pW = pItem->widget();
mTopLayout->removeItem(pItem);
delete pItem;
mTopLayout->removeWidget(pW);
delete pW;
}
delete mTopLayout;
while(!mBottomLayout->isEmpty()) {
QLayoutItem* pItem = mBottomLayout->itemAt(0);
QWidget* pW = pItem->widget();
mBottomLayout->removeItem(pItem);
delete pItem;
mBottomLayout->removeWidget(pW);
delete pW;
}
delete mBottomLayout;
delete mVLayout;
mActions.clear();
mButtons.clear();
}
void UBBackgroundPalette::showEvent(QShowEvent* event)
{
backgroundChanged();
mSlider->setValue(UBApplication::boardController->activeScene()->backgroundGridSize());
connect(mSlider, SIGNAL(valueChanged(int)),
this, SLOT(sliderValueChanged(int)));
QWidget::showEvent(event);
}
void UBBackgroundPalette::sliderValueChanged(int value)
{
UBApplication::boardController->activeScene()->setBackgroundGridSize(value);
}
void UBBackgroundPalette::backgroundChanged()
{
bool dark = UBApplication::boardController->activeScene()->isDarkBackground();
if (dark)
mSliderLabel->setStyleSheet("QLabel { color : white; }");
else
mSliderLabel->setStyleSheet("QLabel { color : black; }");
}
void UBBackgroundPalette::refresh()
{
backgroundChanged();
mSlider->setValue(UBApplication::boardController->activeScene()->backgroundGridSize());
}

@ -0,0 +1,46 @@
#ifndef UBBACKGROUNDPALETTE_H
#define UBBACKGROUNDPALETTE_H
#include "gui/UBActionPalette.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "domain/UBGraphicsScene.h"
class UBBackgroundPalette : public UBActionPalette
{
Q_OBJECT
public:
UBBackgroundPalette(QList<QAction*> actions, QWidget* parent = 0);
UBBackgroundPalette(QWidget* parent = 0);
void addAction(QAction *action);
void setActions(QList<QAction *> actions);
void clearLayout();
public slots:
void showEvent(QShowEvent* event);
void backgroundChanged();
void refresh();
protected slots:
void sliderValueChanged(int value);
protected:
virtual void updateLayout();
void init();
QVBoxLayout* mVLayout;
QHBoxLayout* mTopLayout;
QHBoxLayout* mBottomLayout;
QSlider* mSlider;
QLabel* mSliderLabel;
};
#endif // UBBACKGROUNDPALETTE_H

@ -40,7 +40,8 @@ HEADERS += src/gui/UBThumbnailView.h \
src/gui/UBFeaturesActionBar.h \ src/gui/UBFeaturesActionBar.h \
src/gui/UBMessagesDialog.h \ src/gui/UBMessagesDialog.h \
src/gui/UBOpenSankoreImporterWidget.h \ src/gui/UBOpenSankoreImporterWidget.h \
src/gui/UBStartupHintsPalette.h src/gui/UBStartupHintsPalette.h \
src/gui/UBBackgroundPalette.h
SOURCES += src/gui/UBThumbnailView.cpp \ SOURCES += src/gui/UBThumbnailView.cpp \
src/gui/UBFloatingPalette.cpp \ src/gui/UBFloatingPalette.cpp \
src/gui/UBToolbarButtonGroup.cpp \ src/gui/UBToolbarButtonGroup.cpp \
@ -83,7 +84,8 @@ SOURCES += src/gui/UBThumbnailView.cpp \
src/gui/UBFeaturesActionBar.cpp \ src/gui/UBFeaturesActionBar.cpp \
src/gui/UBMessagesDialog.cpp \ src/gui/UBMessagesDialog.cpp \
src/gui/UBOpenSankoreImporterWidget.cpp \ src/gui/UBOpenSankoreImporterWidget.cpp \
src/gui/UBStartupHintsPalette.cpp src/gui/UBStartupHintsPalette.cpp \
src/gui/UBBackgroundPalette.cpp
win32:SOURCES += src/gui/UBKeyboardPalette_win.cpp win32:SOURCES += src/gui/UBKeyboardPalette_win.cpp
macx:OBJECTIVE_SOURCES += src/gui/UBKeyboardPalette_mac.mm macx:OBJECTIVE_SOURCES += src/gui/UBKeyboardPalette_mac.mm
linux-g++:SOURCES += src/gui/UBKeyboardPalette_linux.cpp linux-g++:SOURCES += src/gui/UBKeyboardPalette_linux.cpp

@ -58,11 +58,8 @@ UBAbstractDrawRuler::UBAbstractDrawRuler()
: mShowButtons(false) : mShowButtons(false)
, mAntiScaleRatio(1.0) , mAntiScaleRatio(1.0)
{ {
//we actually need to evaluate pixels per millimeter
QDesktopWidget* desktop = UBApplication::desktop();
int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
sPixelsPerMillimeter = qRound(dpiCommon / UBGeometryUtils::inchSize);
sPixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize();
} }
void UBAbstractDrawRuler::create(QGraphicsItem& item) void UBAbstractDrawRuler::create(QGraphicsItem& item)

@ -92,7 +92,7 @@ protected:
static const int sFillTransparency; static const int sFillTransparency;
static const int sDrawTransparency; static const int sDrawTransparency;
static const int sRoundingRadius; static const int sRoundingRadius;
int sPixelsPerMillimeter; int sPixelsPerCentimeter;
}; };
#endif #endif

@ -65,10 +65,6 @@ UBGraphicsCompass::UBGraphicsCompass()
, mDrewCenterCross(false) , mDrewCenterCross(false)
{ {
setRect(sDefaultRect); setRect(sDefaultRect);
//TODO claudio: remove code duplication
QDesktopWidget* desktop = UBApplication::desktop();
int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
mPixelsPerMillimeter = qRound(dpiCommon / 25.4f);
setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -427,7 +423,9 @@ void UBGraphicsCompass::paintAngleDisplay(QPainter *painter)
void UBGraphicsCompass::paintRadiusDisplay(QPainter *painter) void UBGraphicsCompass::paintRadiusDisplay(QPainter *painter)
{ {
qreal radiusInCentimeters = rect().width() / (mPixelsPerMillimeter * 10); double pixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize();
qreal radiusInCentimeters = rect().width() / pixelsPerCentimeter;
QString format = rect().width() >= sDisplayRadiusUnitMinLength ? "%1 cm" : "%1"; QString format = rect().width() >= sDisplayRadiusUnitMinLength ? "%1 cm" : "%1";
QString radiusText = QString(format).arg(radiusInCentimeters, 0, 'f', 1); QString radiusText = QString(format).arg(radiusInCentimeters, 0, 'f', 1);

@ -123,7 +123,6 @@ class UBGraphicsCompass: public QObject, public QGraphicsRectItem, public UBItem
QGraphicsSvgItem* mResizeSvgItem; QGraphicsSvgItem* mResizeSvgItem;
qreal mAntiScaleRatio; qreal mAntiScaleRatio;
bool mDrewCenterCross; bool mDrewCenterCross;
int mPixelsPerMillimeter;
// Constants // Constants
static const int sNeedleLength = 18; static const int sNeedleLength = 18;

@ -176,20 +176,44 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter)
painter->save(); painter->save();
painter->setFont(font()); painter->setFont(font());
QFontMetricsF fontMetrics(painter->font()); QFontMetricsF fontMetrics(painter->font());
for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++)
{ // Update the width of one "centimeter" to correspond to the width of the background grid (whether it is displayed or not)
int graduationX = rotationCenter().x() + sPixelsPerMillimeter * millimeters; sPixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize();
int graduationHeight = (0 == millimeters % UBGeometryUtils::millimetersPerCentimeter) ?
UBGeometryUtils::centimeterGraduationHeight : double pixelsPerMillimeter = double(sPixelsPerCentimeter)/10.0;
((0 == millimeters % UBGeometryUtils::millimetersPerHalfCentimeter) ? int rulerLengthInMillimeters = (rect().width() - sLeftEdgeMargin - sRoundingRadius)/pixelsPerMillimeter;
UBGeometryUtils::halfCentimeterGraduationHeight : UBGeometryUtils::millimeterGraduationHeight);
painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() + graduationHeight)); // When a "centimeter" is too narrow, we only display every 5th number, and every 5th millimeter mark
painter->drawLine(QLine(graduationX, rotationCenter().y() + rect().height(), graduationX, rotationCenter().y() + rect().height() - graduationHeight)); double numbersWidth = fontMetrics.width("00");
if (0 == millimeters % UBGeometryUtils::millimetersPerCentimeter) bool shouldDisplayAllNumbers = (numbersWidth <= (sPixelsPerCentimeter - 5));
for (int millimeters(0); millimeters < rulerLengthInMillimeters; millimeters++) {
double graduationX = rotationCenter().x() + pixelsPerMillimeter * millimeters;
double graduationHeight = 0;
if (millimeters % UBGeometryUtils::millimetersPerCentimeter == 0)
graduationHeight = UBGeometryUtils::centimeterGraduationHeight;
else if (millimeters % UBGeometryUtils::millimetersPerHalfCentimeter == 0)
graduationHeight = UBGeometryUtils::halfCentimeterGraduationHeight;
else
graduationHeight = UBGeometryUtils::millimeterGraduationHeight;
if (shouldDisplayAllNumbers || millimeters % UBGeometryUtils::millimetersPerHalfCentimeter == 0) {
painter->drawLine(QLineF(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() + graduationHeight));
painter->drawLine(QLineF(graduationX, rotationCenter().y() + rect().height(), graduationX, rotationCenter().y() + rect().height() - graduationHeight));
}
if ((shouldDisplayAllNumbers && millimeters % UBGeometryUtils::millimetersPerCentimeter == 0)
|| millimeters % (UBGeometryUtils::millimetersPerCentimeter*5) == 0)
{ {
QString text = QString("%1").arg((int)(millimeters / UBGeometryUtils::millimetersPerCentimeter)); QString text = QString("%1").arg((int)(millimeters / UBGeometryUtils::millimetersPerCentimeter));
if (graduationX + fontMetrics.width(text) / 2 < rect().right())
{ if (graduationX + fontMetrics.width(text) / 2 < rect().right()) {
qreal textWidth = fontMetrics.width(text); qreal textWidth = fontMetrics.width(text);
qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5; qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5;
painter->drawText( painter->drawText(
@ -201,7 +225,10 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter)
} }
} }
} }
painter->restore(); painter->restore();
} }
void UBGraphicsRuler::paintRotationCenter(QPainter *painter) void UBGraphicsRuler::paintRotationCenter(QPainter *painter)
@ -252,7 +279,7 @@ QRectF UBGraphicsRuler::closeButtonRect() const
closePixmap.height() * mAntiScaleRatio); closePixmap.height() * mAntiScaleRatio);
QPointF closeRectCenter( QPointF closeRectCenter(
rect().left() + sLeftEdgeMargin + sPixelsPerMillimeter * 5, rect().left() + sLeftEdgeMargin + sPixelsPerCentimeter/2,
rect().center().y()); rect().center().y());
QPointF closeRectTopLeft( QPointF closeRectTopLeft(
@ -270,9 +297,9 @@ QRectF UBGraphicsRuler::rotateButtonRect() const
rotatePixmap.width() * mAntiScaleRatio, rotatePixmap.width() * mAntiScaleRatio,
rotatePixmap.height() * mAntiScaleRatio); rotatePixmap.height() * mAntiScaleRatio);
int centimeters = (int)(rect().width() - sLeftEdgeMargin - resizeButtonRect().width()) / (int)(10 * sPixelsPerMillimeter); int centimeters = (int)(rect().width() - sLeftEdgeMargin - resizeButtonRect().width()) / (sPixelsPerCentimeter);
QPointF rotateRectCenter( QPointF rotateRectCenter(
rect().left() + sLeftEdgeMargin + (centimeters - 0.5) * 10 * sPixelsPerMillimeter, rect().left() + sLeftEdgeMargin + (centimeters - 0.5) * sPixelsPerCentimeter,
rect().center().y()); rect().center().y());
QPointF rotateRectTopLeft( QPointF rotateRectTopLeft(

@ -349,14 +349,27 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
painter->setFont(font()); painter->setFont(font());
QFontMetricsF fontMetrics(painter->font()); QFontMetricsF fontMetrics(painter->font());
for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++) // Update the width of one "centimeter" to correspond to the width of the background grid (whether it is displayed or not)
sPixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize();
double pixelsPerMillimeter = double(sPixelsPerCentimeter)/10.0;
// When a "centimeter" is too narrow, we only display every 5th number, and every 5th millimeter mark
double numbersWidth = fontMetrics.width("00");
bool shouldDisplayAllNumbers = (numbersWidth <= (sPixelsPerCentimeter - 5));
for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / pixelsPerMillimeter; millimeters++)
{ {
int graduationX = rotationCenter().x() + kx * sPixelsPerMillimeter * millimeters; double graduationX = rotationCenter().x() + kx * pixelsPerMillimeter * millimeters;
double graduationHeight = 0;
int graduationHeight = (0 == millimeters % UBGeometryUtils::millimetersPerCentimeter) ? if (millimeters % UBGeometryUtils::millimetersPerCentimeter == 0)
UBGeometryUtils::centimeterGraduationHeight : graduationHeight = UBGeometryUtils::centimeterGraduationHeight;
((0 == millimeters % UBGeometryUtils::millimetersPerHalfCentimeter) ?
UBGeometryUtils::halfCentimeterGraduationHeight : UBGeometryUtils::millimeterGraduationHeight); else if (millimeters % UBGeometryUtils::millimetersPerHalfCentimeter == 0)
graduationHeight = UBGeometryUtils::halfCentimeterGraduationHeight;
else
graduationHeight = UBGeometryUtils::millimeterGraduationHeight;
qreal requiredSpace = graduationHeight + SEPARATOR ; qreal requiredSpace = graduationHeight + SEPARATOR ;
/* B____C /* B____C
@ -387,12 +400,14 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
qreal BC = rect().height(); qreal BC = rect().height();
qreal DE = AD * BC / AB, availableSpace = DE; qreal DE = AD * BC / AB, availableSpace = DE;
if (requiredSpace <= availableSpace) if (availableSpace < requiredSpace)
painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() - ky * graduationHeight));
else
break; break;
if (0 == millimeters % UBGeometryUtils::millimetersPerCentimeter) if (shouldDisplayAllNumbers || millimeters % UBGeometryUtils::millimetersPerHalfCentimeter == 0)
painter->drawLine(QLineF(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() - ky * graduationHeight));
if ((shouldDisplayAllNumbers && millimeters % UBGeometryUtils::millimetersPerCentimeter == 0)
|| millimeters % (UBGeometryUtils::millimetersPerCentimeter*5) == 0)
{ {
QString text = QString("%1").arg((int)(millimeters / UBGeometryUtils::millimetersPerCentimeter)); QString text = QString("%1").arg((int)(millimeters / UBGeometryUtils::millimetersPerCentimeter));
qreal textWidth = fontMetrics.width(text); qreal textWidth = fontMetrics.width(text);

Loading…
Cancel
Save