[QGIS Commit] r8676 - in branches/advanced_printing_branch/src:
app/composer ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Jun 24 04:11:12 EDT 2008
Author: mhugent
Date: 2008-06-24 04:11:12 -0400 (Tue, 24 Jun 2008)
New Revision: 8676
Modified:
branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h
branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.h
branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
branches/advanced_printing_branch/src/ui/qgscomposerscalebarwidgetbase.ui
Log:
More scalebar item improvements
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp 2008-06-23 23:22:13 UTC (rev 8675)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp 2008-06-24 08:11:12 UTC (rev 8676)
@@ -106,6 +106,8 @@
{
mComposerMap->setPreviewMode(QgsComposerMap::Rectangle);
}
+
+ mComposerMap->update();
}
void QgsComposerMapWidget::on_mFrameCheckBox_stateChanged(int state)
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp 2008-06-23 23:22:13 UTC (rev 8675)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp 2008-06-24 08:11:12 UTC (rev 8676)
@@ -22,7 +22,7 @@
QgsComposerScaleBar::QgsComposerScaleBar(QgsComposition* composition): QgsComposerItem(composition), mComposerMap(0), mStyle(QgsComposerScaleBar::Single_Box), mSegmentMM(0.0)
{
- mLabelBarSpace = 3.0;
+ applyDefaultSettings();
}
QgsComposerScaleBar::~QgsComposerScaleBar()
@@ -34,7 +34,7 @@
{
//calculate top level of the bar
QFontMetricsF labelFontMetrics(mFont);
- double barTopPosition = labelFontMetrics.height() + mLabelBarSpace;
+ double barTopPosition = fontHeight(painter) + mLabelBarSpace;
switch(mStyle)
{
@@ -87,6 +87,8 @@
mNumSegments = 3;
mNumSegmentsLeft = 1;
+ mNumMapUnitsPerScaleBarUnit = 1.0;
+
mHeight = 5;
mStyle = QgsComposerScaleBar::Single_Box;
@@ -94,8 +96,12 @@
mPen = QPen(QColor(0, 0, 0));
mPen.setWidthF(1.0);
+ mBrush.setColor(QColor(0, 0, 0));
+
mFont.setPointSizeF(8);
+ mLabelBarSpace = 3.0;
+
if(mComposerMap)
{
//calculate mNumUnitsPerSegment
@@ -107,6 +113,7 @@
}
refreshSegmentMM();
+ adjustBoxSize();
}
void QgsComposerScaleBar::drawLabels(QPainter* p)
@@ -117,12 +124,13 @@
}
p->save();
- p->setFont(mFont);
+
+ QFont labelFont(mFont);
+ labelFont.setPointSizeF(mFont.pointSizeF() * fontPointScaleFactor(p));
- QFontMetricsF labelFontMetrics(mFont);
- double fontHeight = labelFontMetrics.height();
+ p->setFont(labelFont);
- double mCurrentXCoord = 0;
+ double mCurrentXCoord = mPen.widthF();
//draw labels of the left segments
for(int i = 0; i < mNumSegmentsLeft; ++i)
@@ -135,7 +143,7 @@
//draw labels of the right segments
for(int i = 0; i < mNumSegments; ++i)
{
- p->drawText(QPointF(mCurrentXCoord, fontHeight), QString::number(currentLabelNumber));
+ p->drawText(QPointF(mCurrentXCoord, fontHeight(p)), QString::number(currentLabelNumber / mNumMapUnitsPerScaleBarUnit) + " " + mUnitLabeling);
mCurrentXCoord += mSegmentMM;
currentLabelNumber += mNumUnitsPerSegment;
}
@@ -154,9 +162,8 @@
//mHeight, mBrush, mPen
p->setPen(mPen);
- p->setBrush(mBrush);
- double mCurrentXCoord = 0;
+ double mCurrentXCoord = mPen.widthF();
bool useColor = true; //alternate brush color/white
@@ -165,11 +172,11 @@
{
if(useColor) //alternating colors
{
- p->setBrush(QColor(255, 255, 255));
+ p->setBrush(mBrush);
}
- else
+ else //white
{
- p->setBrush(QColor(0, 0, 0));
+ p->setBrush(QColor(255, 255, 255));
}
QRectF segmentRect(mCurrentXCoord, barTopPosition, mSegmentMM/mNumSegmentsLeft, mHeight);
p->drawRect(segmentRect);
@@ -182,11 +189,11 @@
{
if(useColor) //alternating colors
{
- p->setBrush(QColor(255, 255, 255));
+ p->setBrush(mBrush);
}
- else
+ else //white
{
- p->setBrush(QColor(0, 0, 0));
+ p->setBrush(QColor(255, 255, 255));
}
QRectF segmentRect(mCurrentXCoord, barTopPosition, mSegmentMM, mHeight);
@@ -198,8 +205,35 @@
p->restore();
}
+void QgsComposerScaleBar::adjustBoxSize()
+{
+ int numFullSegments = mNumSegments;
+ if(mNumSegmentsLeft > 0)
+ {
+ ++numFullSegments;
+ }
+ double width = numFullSegments * mSegmentMM + 2 * mPen.widthF();
+ double height = mHeight + mLabelBarSpace + QFontMetrics(mFont).height();
+ QRectF sceneBox(transform().dx(), transform().dy(), width, height);
+ setSceneRect(sceneBox);
+}
+void QgsComposerScaleBar::update()
+{
+ adjustBoxSize();
+ QgsComposerItem::update();
+}
+
+double QgsComposerScaleBar::fontHeight(QPainter* p) const
+{
+ QFont labelFont(mFont);
+ labelFont.setPointSizeF(mFont.pointSizeF() * fontPointScaleFactor(p));
+ QFontMetricsF labelFontMetrics(labelFont);
+ return labelFontMetrics.height();
+}
+
+
#if 0
#include "qgscomposerscalebar.h"
#include "qgscomposermap.h"
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h 2008-06-23 23:22:13 UTC (rev 8675)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h 2008-06-24 08:11:12 UTC (rev 8676)
@@ -50,6 +50,9 @@
double numUnitsPerSegment() const {return mNumUnitsPerSegment;}
void setNumUnitsPerSegment(double units);
+ double numMapUnitsPerScaleBarUnit() const {return mNumMapUnitsPerScaleBarUnit;}
+ void setNumMapUnitsPerScaleBarUnit(double d) {mNumMapUnitsPerScaleBarUnit = d;}
+
QString unitLabeling() const {return mUnitLabeling;}
void setUnitLabeling(const QString& label){mUnitLabeling = label;}
@@ -73,7 +76,12 @@
void setStyle(QgsComposerScaleBar::Style style){mStyle = style;}
-
+ /**Sets box size suitable to content*/
+ void adjustBoxSize();
+
+ /**Adjusts box size and calls QgsComposerItem::update()*/
+ void update();
+
protected:
/**Reference to composer map object*/
@@ -84,6 +92,9 @@
int mNumSegmentsLeft;
/**Size of a segment (in map units)*/
double mNumUnitsPerSegment;
+ /**Number of map units per scale bar units (e.g. 1000 to have km for a map with m units)*/
+ double mNumMapUnitsPerScaleBarUnit;
+
/**Labeling of map units*/
QString mUnitLabeling;
/**Font*/
@@ -111,6 +122,9 @@
/**Draws this bar using single box style
@param barTopPosition Item coordinates of the bar top. Necessary because of Labels*/
void drawScaleBarSingleBox(QPainter* p, double barTopPosition) const;
+
+ /**Returns height of font considering font scale factor for the given painter*/
+ double fontHeight(QPainter* p) const;
};
#endif //QGSCOMPOSERSCALEBAR_H
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp 2008-06-23 23:22:13 UTC (rev 8675)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp 2008-06-24 08:11:12 UTC (rev 8676)
@@ -17,6 +17,8 @@
#include "qgscomposerscalebarwidget.h"
#include "qgscomposermap.h"
#include "qgscomposerscalebar.h"
+#include <QColorDialog>
+#include <QFontDialog>
#include <QWidget>
QgsComposerScaleBarWidget::QgsComposerScaleBarWidget(QgsComposerScaleBar* scaleBar): QWidget(), mComposerScaleBar(scaleBar)
@@ -107,6 +109,7 @@
mSegmentSizeSpinBox->setValue(mComposerScaleBar->numUnitsPerSegment());
mLineWidthSpinBox->setValue(mComposerScaleBar->pen().widthF());
mHeightSpinBox->setValue(mComposerScaleBar->height());
+ mMapUnitsPerBarUnitSpinBox->setValue(mComposerScaleBar->numMapUnitsPerScaleBarUnit());
//map combo box
if(mComposerScaleBar->composerMap())
@@ -173,3 +176,71 @@
mComposerScaleBar->update();
}
+void QgsComposerScaleBarWidget::on_mHeightSpinBox_valueChanged(int i)
+{
+if(!mComposerScaleBar)
+ {
+ return;
+ }
+ mComposerScaleBar->setHeight(i);
+ mComposerScaleBar->update();
+}
+
+void QgsComposerScaleBarWidget::on_mFontButton_clicked()
+{
+ if(!mComposerScaleBar)
+ {
+ return;
+ }
+
+ bool dialogAccepted;
+ QFont oldFont = mComposerScaleBar->font();
+ QFont newFont = QFontDialog::getFont(&dialogAccepted, oldFont, 0);
+ if(dialogAccepted)
+ {
+ mComposerScaleBar->setFont(newFont);
+ }
+ mComposerScaleBar->update();
+}
+
+void QgsComposerScaleBarWidget::on_mColorPushButton_clicked()
+{
+ if(!mComposerScaleBar)
+ {
+ return;
+ }
+
+ QColor oldColor = mComposerScaleBar->brush().color();
+ QColor newColor = QColorDialog::getColor(oldColor, 0);
+
+ if(!newColor.isValid()) //user canceled the dialog
+ {
+ return;
+ }
+
+ QBrush newBrush(newColor);
+ mComposerScaleBar->setBrush(newBrush);
+ mComposerScaleBar->update();
+}
+
+void QgsComposerScaleBarWidget::on_mUnitLabelLineEdit_textChanged(const QString& text)
+{
+ if(!mComposerScaleBar)
+ {
+ return;
+ }
+
+ mComposerScaleBar->setUnitLabeling(text);
+ mComposerScaleBar->update();
+}
+
+void QgsComposerScaleBarWidget::on_mMapUnitsPerBarUnitSpinBox_valueChanged(double d)
+{
+ if(!mComposerScaleBar)
+ {
+ return;
+ }
+
+ mComposerScaleBar->setNumMapUnitsPerScaleBarUnit(d);
+ mComposerScaleBar->update();
+}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.h 2008-06-23 23:22:13 UTC (rev 8675)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.h 2008-06-24 08:11:12 UTC (rev 8676)
@@ -31,10 +31,16 @@
public slots:
void on_mMapComboBox_activated(const QString& text);
+ void on_mHeightSpinBox_valueChanged(int i);
void on_mLineWidthSpinBox_valueChanged(double d);
void on_mSegmentSizeSpinBox_valueChanged(double d);
void on_mSegmentsLeftSpinBox_valueChanged(int i);
void on_mNumberOfSegmentsSpinBox_valueChanged(int i);
+ void on_mUnitLabelLineEdit_textChanged(const QString& text);
+ void on_mMapUnitsPerBarUnitSpinBox_valueChanged(double d);
+ void on_mColorPushButton_clicked();
+ void on_mFontButton_clicked();
+
protected:
void showEvent ( QShowEvent * event );
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp 2008-06-23 23:22:13 UTC (rev 8675)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp 2008-06-24 08:11:12 UTC (rev 8676)
@@ -102,11 +102,11 @@
{
newScaleBar->setComposerMap(mapItemList.at(0));
}
-
+
+ newScaleBar->setSceneRect(QRectF(scenePoint.x(), scenePoint.y(), 20, 20));
newScaleBar->applyDefaultSettings(); //4 segments, 1/5 of composer map width
scene()->addItem(newScaleBar);
emit composerScaleBarAdded(newScaleBar);
- newScaleBar->setSceneRect(QRectF(scenePoint.x(), scenePoint.y(), 20, 20)); //todo: change this...
scene()->clearSelection();
newScaleBar->setSelected(true);
emit selectedItemChanged(newScaleBar);
Modified: branches/advanced_printing_branch/src/ui/qgscomposerscalebarwidgetbase.ui
===================================================================
--- branches/advanced_printing_branch/src/ui/qgscomposerscalebarwidgetbase.ui 2008-06-23 23:22:13 UTC (rev 8675)
+++ branches/advanced_printing_branch/src/ui/qgscomposerscalebarwidgetbase.ui 2008-06-24 08:11:12 UTC (rev 8676)
@@ -5,7 +5,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>303</width>
+ <width>367</width>
<height>487</height>
</rect>
</property>
@@ -86,6 +86,23 @@
<widget class="QLineEdit" name="mUnitLabelLineEdit" />
</item>
<item row="5" column="0" >
+ <widget class="QLabel" name="mMapUnitsPerBarUnitLabel" >
+ <property name="text" >
+ <string>Map units per bar unit:</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="2" >
+ <widget class="QDoubleSpinBox" name="mMapUnitsPerBarUnitSpinBox" >
+ <property name="maximum" >
+ <double>9999999999999.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" >
<widget class="QLabel" name="mMapLabel" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
@@ -104,7 +121,7 @@
</property>
</widget>
</item>
- <item row="5" column="2" >
+ <item row="6" column="2" >
<widget class="QComboBox" name="mMapComboBox" >
<property name="enabled" >
<bool>true</bool>
@@ -117,17 +134,17 @@
</property>
</widget>
</item>
- <item row="6" column="0" >
+ <item row="7" column="0" >
<widget class="QLabel" name="mHeightLabel" >
<property name="text" >
<string>Height (mm):</string>
</property>
</widget>
</item>
- <item row="6" column="2" >
+ <item row="7" column="2" >
<widget class="QSpinBox" name="mHeightSpinBox" />
</item>
- <item row="7" column="0" >
+ <item row="8" column="0" >
<widget class="QLabel" name="mLineWidthLabel" >
<property name="text" >
<string>Line width:</string>
@@ -140,7 +157,7 @@
</property>
</widget>
</item>
- <item row="7" column="2" >
+ <item row="8" column="2" >
<widget class="QDoubleSpinBox" name="mLineWidthSpinBox" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
@@ -159,7 +176,7 @@
</property>
</widget>
</item>
- <item row="8" column="0" >
+ <item row="9" column="0" >
<widget class="QPushButton" name="mFontButton" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
@@ -172,14 +189,14 @@
</property>
</widget>
</item>
- <item row="8" column="2" >
+ <item row="9" column="2" >
<widget class="QPushButton" name="mColorPushButton" >
<property name="text" >
<string>Color...</string>
</property>
</widget>
</item>
- <item row="9" column="1" >
+ <item row="10" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
@@ -187,7 +204,7 @@
<property name="sizeHint" >
<size>
<width>20</width>
- <height>51</height>
+ <height>61</height>
</size>
</property>
</spacer>
More information about the QGIS-commit
mailing list