add option to draw intermediate grid lines

preferencesAboutTextFull
letsfindaway 4 years ago
parent b30b3fd522
commit 541083a972
  1. 16
      resources/forms/mainWindow.ui
  2. 18
      src/adaptors/UBSvgSubsetAdaptor.cpp
  3. 28
      src/board/UBBoardView.cpp
  4. 1
      src/core/UBSettings.cpp
  5. 1
      src/core/UBSettings.h
  6. 10
      src/domain/UBGraphicsScene.cpp
  7. 7
      src/domain/UBGraphicsScene.h
  8. 20
      src/gui/UBBackgroundPalette.cpp
  9. 4
      src/gui/UBBackgroundPalette.h

@ -1686,6 +1686,22 @@
<string>Reset grid size</string>
</property>
</action>
<action name="actionDrawIntermediateGridLines">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../OpenBoard.qrc">
<normaloff>:/images/minus.svg</normaloff>
<normalon>:/images/save.svg</normalon>:/images/minus.svg</iconset>
</property>
<property name="text">
<string>Draw intermediate grid lines</string>
</property>
<property name="toolTip">
<string>Draw intermediate grid lines</string>
</property>
</action>
</widget>
<resources>
<include location="../OpenBoard.qrc"/>

@ -469,6 +469,14 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx
mScene->setBackgroundGridSize(gridSize);
}
QStringRef ubIntermediateLines = mXmlReader.attributes().value(mNamespaceUri, "intermediate-lines");
if (!ubIntermediateLines.isNull()) {
bool intermediateLines = ubIntermediateLines.toInt();
mScene->setIntermediateLines(intermediateLines);
}
}
QStringRef ubRuledBackground = mXmlReader.attributes().value(mNamespaceUri, "ruled-background");
@ -484,6 +492,14 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx
mScene->setBackgroundGridSize(gridSize);
}
QStringRef ubIntermediateLines = mXmlReader.attributes().value(mNamespaceUri, "intermediate-lines");
if (!ubIntermediateLines.isNull()) {
bool intermediateLines = ubIntermediateLines.toInt();
mScene->setIntermediateLines(intermediateLines);
}
}
UBPageBackground bg;
@ -1140,8 +1156,10 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement(UBDocumentProxy* pro
if (crossedBackground || ruledBackground) {
int gridSize = mScene->backgroundGridSize();
bool intermediateLines = mScene->intermediateLines();
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "grid-size", QString::number(gridSize));
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "intermediate-lines", QString::number(intermediateLines));
}
QDesktopWidget* desktop = UBApplication::desktop();

@ -1629,6 +1629,7 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
}
qreal gridSize = scene()->backgroundGridSize();
bool intermediateLines = scene()->intermediateLines();
painter->setPen (bgCrossColor);
@ -1647,6 +1648,22 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
{
painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ());
}
if (intermediateLines) {
QColor intermediateColor = bgCrossColor;
intermediateColor.setAlphaF(0.5 * bgCrossColor.alphaF());
painter->setPen(intermediateColor);
for (qreal yPos = firstY - gridSize/2; yPos < rect.y () + rect.height (); yPos += gridSize)
{
painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
}
for (qreal xPos = firstX - gridSize/2; xPos < rect.x () + rect.width (); xPos += gridSize)
{
painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ());
}
}
}
if (scene() && scene()->pageBackground() == UBPageBackground::ruled)
@ -1657,6 +1674,17 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
{
painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
}
if (intermediateLines) {
QColor intermediateColor = bgCrossColor;
intermediateColor.setAlphaF(0.5 * bgCrossColor.alphaF());
painter->setPen(intermediateColor);
for (qreal yPos = firstY - gridSize/2; yPos < rect.y () + rect.height (); yPos += gridSize)
{
painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
}
}
}
}

@ -50,6 +50,7 @@ int UBSettings::crossSize = 24;
int UBSettings::defaultCrossSize = 24;
int UBSettings::minCrossSize = 12;
int UBSettings::maxCrossSize = 96; //TODO: user-settable?
bool UBSettings::intermediateLines = false;
int UBSettings::colorPaletteSize = 5;
int UBSettings::objectFrameWidth = 20;
int UBSettings::boardMargin = 10;

@ -191,6 +191,7 @@ class UBSettings : public QObject
static int defaultCrossSize;
static int minCrossSize;
static int maxCrossSize;
static bool intermediateLines;
static int colorPaletteSize;
static int objectFrameWidth;

@ -359,6 +359,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
}
mBackgroundGridSize = UBSettings::settings()->crossSize;
mIntermediateLines = UBSettings::settings()->intermediateLines;
// Just for debug. Do not delete please
// connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
@ -1155,6 +1156,15 @@ void UBGraphicsScene::setBackgroundGridSize(int pSize)
}
}
void UBGraphicsScene::setIntermediateLines(bool checked)
{
mIntermediateLines = checked;
setModified(true);
foreach(QGraphicsView* view, views())
view->resetCachedContent();
}
void UBGraphicsScene::setDrawingMode(bool bModeDesktop)
{
mIsDesktopMode = bModeDesktop;

@ -230,6 +230,11 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
return mBackgroundGridSize;
}
bool intermediateLines() const
{
return mIntermediateLines;
}
bool hasBackground()
{
return (mBackgroundObject != 0);
@ -359,6 +364,7 @@ public slots:
void setBackground(bool pIsDark, UBPageBackground pBackground);
void setBackgroundZoomFactor(qreal zoom);
void setBackgroundGridSize(int pSize);
void setIntermediateLines(bool checked);
void setDrawingMode(bool bModeDesktop);
void deselectAllItems();
@ -442,6 +448,7 @@ public slots:
bool mDarkBackground;
UBPageBackground mPageBackground;
int mBackgroundGridSize;
bool mIntermediateLines;
bool mIsDesktopMode;
qreal mZoomFactor;

@ -48,6 +48,7 @@ void UBBackgroundPalette::init()
mSlider->setTracking(true); // valueChanged() is emitted during movement and not just upon releasing the slider
mSliderLabel = new QLabel(tr("Grid size"));
mIntermediateLinesLabel = new QLabel(tr("Draw intermediate grid lines"));
mResetDefaultGridSizeButton = createPaletteButton(UBApplication::mainWindow->actionDefaultGridSize, this);
mResetDefaultGridSizeButton->setFixedSize(24,24);
@ -55,11 +56,22 @@ void UBBackgroundPalette::init()
connect(UBApplication::mainWindow->actionDefaultGridSize, SIGNAL(triggered()), this, SLOT(defaultBackgroundGridSize()));
mDrawIntermediateLinesCheckBox = createPaletteButton(UBApplication::mainWindow->actionDrawIntermediateGridLines, this);
mDrawIntermediateLinesCheckBox->setFixedSize(24,24);
mDrawIntermediateLinesCheckBox->setCheckable(true);
mActions << UBApplication::mainWindow->actionDrawIntermediateGridLines;
mButtons.removeLast(); // don't add to button group
connect(UBApplication::mainWindow->actionDrawIntermediateGridLines, SIGNAL(toggled(bool)), this, SLOT(toggleIntermediateLines(bool)));
mBottomLayout->addSpacing(16);
mBottomLayout->addWidget(mSliderLabel);
mBottomLayout->addWidget(mSlider);
mBottomLayout->addWidget(mResetDefaultGridSizeButton);
mBottomLayout->addSpacing(16);
mBottomLayout->addWidget(mIntermediateLinesLabel);
mBottomLayout->addWidget(mDrawIntermediateLinesCheckBox);
mBottomLayout->addSpacing(16);
updateLayout();
}
@ -137,6 +149,8 @@ void UBBackgroundPalette::showEvent(QShowEvent* event)
connect(mSlider, SIGNAL(valueChanged(int)),
this, SLOT(sliderValueChanged(int)));
mDrawIntermediateLinesCheckBox->setChecked(UBApplication::boardController->activeScene()->intermediateLines());
QWidget::showEvent(event);
}
@ -152,6 +166,12 @@ void UBBackgroundPalette::defaultBackgroundGridSize()
sliderValueChanged(UBSettings::settings()->defaultCrossSize);
}
void UBBackgroundPalette::toggleIntermediateLines(bool checked)
{
UBApplication::boardController->activeScene()->setIntermediateLines(checked);
UBSettings::settings()->intermediateLines = checked; // since this function is called (indirectly, by refresh) when we switch scenes, the settings will always have the current scene's value.
}
void UBBackgroundPalette::backgroundChanged()
{
bool dark = UBApplication::boardController->activeScene()->isDarkBackground();

@ -28,6 +28,7 @@ class UBBackgroundPalette : public UBActionPalette
protected slots:
void sliderValueChanged(int value);
void defaultBackgroundGridSize();
void toggleIntermediateLines(bool checked);
protected:
virtual void updateLayout();
@ -40,8 +41,9 @@ class UBBackgroundPalette : public UBActionPalette
QSlider* mSlider;
QLabel* mSliderLabel;
QLabel* mIntermediateLinesLabel;
UBActionPaletteButton* mResetDefaultGridSizeButton;
UBActionPaletteButton* mDrawIntermediateLinesCheckBox;
};

Loading…
Cancel
Save