Skip to content

Commit 521f646

Browse files
author
g_j_m
committedNov 15, 2007
Fix for ticket #150 (added ability to set the copyright text colour).
Also removed use of Qt3Support code in the plugin git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7410 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

4 files changed

+189
-113
lines changed

4 files changed

+189
-113
lines changed
 

‎src/plugins/copyright_label/plugin.cpp

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ email : tim@linfiniti.com
3030

3131
#include "plugin.h"
3232

33-
#include <Q3Button>
34-
#include <Q3PaintDeviceMetrics>
35-
#include <Q3SimpleRichText>
3633
#include <QPainter>
3734
#include <QMenu>
3835
#include <QDate>
36+
#include <QTextDocument>
37+
#include <QMatrix>
3938

4039
//non qt includes
4140
#include <iostream>
41+
#include <cmath>
4242

4343
//the gui subclass
4444
#include "plugingui.h"
@@ -102,15 +102,14 @@ void QgsCopyrightLabelPlugin::projectRead()
102102
QString defString;
103103

104104
now = QDate::currentDate();
105-
defString = "&copy QGIS " + now.toString("yyyy");
105+
defString = "&copy; QGIS " + now.toString("yyyy");
106106

107107
mQFont.setFamily(QgsProject::instance()->readEntry("CopyrightLabel","/FontName","Sans Serif"));
108108
mQFont.setPointSize(QgsProject::instance()->readNumEntry("CopyrightLabel","/FontSize",9));
109109
mLabelQString = QgsProject::instance()->readEntry("CopyrightLabel","/Label", defString);
110110
mPlacementIndex = QgsProject::instance()->readNumEntry("CopyrightLabel","/Placement",3);
111111
mEnable = QgsProject::instance()->readBoolEntry("CopyrightLabel","/Enabled",true);
112-
// todo - read & store state of font color
113-
mLabelQColor = QColor(Qt::black);
112+
mLabelQColor.setNamedColor(QgsProject::instance()->readEntry("CopyrightLabel", "/Color", "#000000")); // default color is black
114113
}
115114
//method defined in interface
116115
void QgsCopyrightLabelPlugin::help()
@@ -135,6 +134,7 @@ void QgsCopyrightLabelPlugin::run()
135134
myPluginGui->setText(mLabelQString);
136135
myPluginGui->setPlacementLabels(mPlacementLabels);
137136
myPluginGui->setPlacement(mPlacementIndex);
137+
myPluginGui->setColor(mLabelQColor);
138138
myPluginGui->setEnabled(mEnable);
139139
myPluginGui->show();
140140
}
@@ -149,54 +149,52 @@ void QgsCopyrightLabelPlugin::renderLabel(QPainter * theQPainter)
149149
//Large IF statement to enable/disable copyright label
150150
if (mEnable)
151151
{
152-
//@todo softcode this!myQSimpleText.height()
153152
// need width/height of paint device
154-
Q3PaintDeviceMetrics myMetrics( theQPainter->device() );
155-
int myHeight = myMetrics.height();
156-
int myWidth = myMetrics.width();
157-
// FIXME: hard coded cludge for getting a colorgroup. Needs to be replaced
158-
Q3Button * myQButton =new Q3Button();
159-
QColorGroup myQColorGroup = myQButton->colorGroup();
160-
delete myQButton;
161-
162-
Q3SimpleRichText myQSimpleText(mLabelQString, mQFont);
163-
myQSimpleText.setWidth( theQPainter, myWidth-10 );
164-
165-
//Get canvas dimensions
166-
int myYOffset = myHeight;
167-
int myXOffset = myWidth;
168-
153+
int myHeight = theQPainter->device()->height();
154+
int myWidth = theQPainter->device()->width();
155+
156+
QTextDocument text;
157+
text.setDefaultFont(mQFont);
158+
// To set the text colour in a QTextDocument we use a CSS style
159+
QString style = "<style type=\"text/css\"> p {color: " +
160+
mLabelQColor.name() + "}</style>";
161+
text.setHtml(style + "<p>" + mLabelQString + "</p>");
162+
QSizeF size = text.size();
163+
164+
float myXOffset(0), myYOffset(0);
169165
//Determine placement of label from form combo box
170166
switch (mPlacementIndex)
171167
{
172168
case 0: // Bottom Left
173169
//Define bottom left hand corner start point
174-
myYOffset = myYOffset - (myQSimpleText.height()+5);
170+
myYOffset = myHeight - size.height() + 5;
175171
myXOffset = 5;
176172
break;
177173
case 1: // Top left
178174
//Define top left hand corner start point
179-
myYOffset = 5;
175+
myYOffset = 0;;
180176
myXOffset = 5;
181177
break;
182178
case 2: // Top Right
183179
//Define top right hand corner start point
184-
myYOffset = 5;
185-
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
180+
myYOffset = 0;
181+
myXOffset = myWidth - (size.width() + 5);
186182
break;
187183
case 3: // Bottom Right
188184
//Define bottom right hand corner start point
189-
myYOffset = myYOffset - (myQSimpleText.height()+5);
190-
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
185+
myYOffset = myHeight - size.height() + 5;
186+
myXOffset = myWidth - (size.width() + 5);
191187
break;
192188
default:
193189
std::cerr << "Unknown placement index of " << mPlacementIndex << '\n';
194190
}
195191

196192
//Paint label to canvas
197-
QRect myRect(myXOffset,myYOffset,myQSimpleText.widthUsed(),myQSimpleText.height());
198-
myQSimpleText.draw (theQPainter, myXOffset, myYOffset, myRect, myQColorGroup);
199-
193+
QMatrix worldMatrix = theQPainter->worldMatrix();
194+
theQPainter->translate(myXOffset, myYOffset);
195+
text.drawContents(theQPainter);
196+
// Put things back how they were
197+
theQPainter->setWorldMatrix(worldMatrix);
200198
}
201199
}
202200
// Unload the plugin by cleaning up the GUI
@@ -235,9 +233,7 @@ void QgsCopyrightLabelPlugin::setLabel(QString theLabelQString)
235233
void QgsCopyrightLabelPlugin::setColor(QColor theQColor)
236234
{
237235
mLabelQColor = theQColor;
238-
QgsProject::instance()->writeEntry("CopyrightLabel","/ColorRedPart", mLabelQColor.red());
239-
QgsProject::instance()->writeEntry("CopyrightLabel","/ColorGreenPart", mLabelQColor.green());
240-
QgsProject::instance()->writeEntry("CopyrightLabel","/ColorBluePart", mLabelQColor.blue());
236+
QgsProject::instance()->writeEntry("CopyrightLabel", "/Color", mLabelQColor.name());
241237
refreshCanvas();
242238
}
243239

‎src/plugins/copyright_label/plugingui.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "qgscontexthelp.h"
1414

1515
//qt includes
16+
#include <QColorDialog>
1617

1718
//standard includes
1819

@@ -53,6 +54,19 @@ void QgsCopyrightLabelPluginGui::on_buttonBox_helpRequested()
5354
QgsContextHelp::run(context_id);
5455
}
5556

57+
void QgsCopyrightLabelPluginGui::on_pbnColorChooser_clicked()
58+
{
59+
QColor c = QColorDialog::getColor();
60+
if (c.isValid())
61+
{
62+
pbnColorChooser->setColor(c);
63+
QTextCursor cursor = txtCopyrightText->textCursor();
64+
txtCopyrightText->selectAll();
65+
txtCopyrightText->setTextColor(c);
66+
txtCopyrightText->setTextCursor(cursor);
67+
}
68+
}
69+
5670
void QgsCopyrightLabelPluginGui::setEnabled(bool theBool)
5771
{
5872
cboxEnabled->setChecked(theBool);
@@ -73,3 +87,12 @@ void QgsCopyrightLabelPluginGui::setPlacement(int placementIndex)
7387
{
7488
cboPlacement->setCurrentIndex(placementIndex);
7589
}
90+
91+
void QgsCopyrightLabelPluginGui::setColor(QColor color)
92+
{
93+
pbnColorChooser->setColor(color);
94+
QTextCursor cursor = txtCopyrightText->textCursor();
95+
txtCopyrightText->selectAll();
96+
txtCopyrightText->setTextColor(color);
97+
txtCopyrightText->setTextCursor(cursor);
98+
}

‎src/plugins/copyright_label/plugingui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ Q_OBJECT;
2828
void setText(QString);
2929
void setPlacementLabels(QStringList&);
3030
void setPlacement(int);
31+
void setColor(QColor);
3132
void setEnabled(bool);
3233

3334
private slots:
3435
void on_buttonBox_accepted();
3536
void on_buttonBox_rejected();
3637
void on_buttonBox_helpRequested();
38+
void on_pbnColorChooser_clicked();
3739

3840
private:
3941
static const int context_id = 32338213;

‎src/plugins/copyright_label/pluginguibase.ui

Lines changed: 134 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<rect>
66
<x>0</x>
77
<y>0</y>
8-
<width>578</width>
8+
<width>556</width>
99
<height>489</height>
1010
</rect>
1111
</property>
@@ -22,6 +22,54 @@
2222
<property name="spacing" >
2323
<number>6</number>
2424
</property>
25+
<item row="3" column="2" >
26+
<layout class="QHBoxLayout" >
27+
<property name="margin" >
28+
<number>0</number>
29+
</property>
30+
<property name="spacing" >
31+
<number>6</number>
32+
</property>
33+
<item>
34+
<widget class="QLabel" name="label" >
35+
<property name="text" >
36+
<string>Color</string>
37+
</property>
38+
</widget>
39+
</item>
40+
<item>
41+
<widget class="QgsColorButton" name="pbnColorChooser" >
42+
<property name="sizePolicy" >
43+
<sizepolicy>
44+
<hsizetype>0</hsizetype>
45+
<vsizetype>7</vsizetype>
46+
<horstretch>0</horstretch>
47+
<verstretch>0</verstretch>
48+
</sizepolicy>
49+
</property>
50+
<property name="minimumSize" >
51+
<size>
52+
<width>100</width>
53+
<height>0</height>
54+
</size>
55+
</property>
56+
</widget>
57+
</item>
58+
<item>
59+
<spacer>
60+
<property name="orientation" >
61+
<enum>Qt::Horizontal</enum>
62+
</property>
63+
<property name="sizeHint" >
64+
<size>
65+
<width>40</width>
66+
<height>20</height>
67+
</size>
68+
</property>
69+
</spacer>
70+
</item>
71+
</layout>
72+
</item>
2573
<item row="0" column="2" >
2674
<widget class="QTextEdit" name="textEdit3" >
2775
<property name="readOnly" >
@@ -30,58 +78,59 @@
3078
<property name="html" >
3179
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
3280
p, li { white-space: pre-wrap; }
33-
&lt;/style>&lt;/head>&lt;body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">
34-
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;">&lt;span style=" font-size:12pt;">Description&lt;/span>&lt;/p>
35-
&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;">&lt;/p>
36-
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;">Enter your copyright label below. This plugin supports basic html markup tags for formatting the label. For example:&lt;/p>
37-
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;">&lt;span style=" font-weight:600;">&amp;lt;B&amp;gt; Bold text &amp;lt;/B&amp;gt; &lt;/span>&lt;/p>
38-
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt; font-weight:600;">&lt;span style=" font-weight:400; font-style:italic;">&amp;lt;I&amp;gt; Italics &amp;lt;/I&amp;gt;&lt;/span>&lt;/p>
39-
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt; font-style:italic;">&lt;span style=" font-style:normal;">(note: &amp;amp;copy; gives a copyright symbol)&lt;/span>&lt;/p>&lt;/body>&lt;/html></string>
81+
&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
82+
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-size:12pt;">Description&lt;/span>&lt;/p>
83+
&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>
84+
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Enter your copyright label below. This plugin supports basic html markup tags for formatting the label. For example:&lt;/p>
85+
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-weight:600;">&amp;lt;B&amp;gt; Bold text &amp;lt;/B&amp;gt; &lt;/span>&lt;/p>
86+
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;">&lt;span style=" font-weight:400; font-style:italic;">&amp;lt;I&amp;gt; Italics &amp;lt;/I&amp;gt;&lt;/span>&lt;/p>
87+
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-style:italic;">&lt;span style=" font-style:normal;">(note: &amp;amp;copy; gives a copyright symbol)&lt;/span>&lt;/p>&lt;/body>&lt;/html></string>
4088
</property>
4189
</widget>
4290
</item>
91+
<item row="4" column="2" >
92+
<layout class="QHBoxLayout" >
93+
<property name="margin" >
94+
<number>0</number>
95+
</property>
96+
<property name="spacing" >
97+
<number>6</number>
98+
</property>
99+
<item>
100+
<spacer>
101+
<property name="orientation" >
102+
<enum>Qt::Horizontal</enum>
103+
</property>
104+
<property name="sizeType" >
105+
<enum>QSizePolicy::Expanding</enum>
106+
</property>
107+
<property name="sizeHint" >
108+
<size>
109+
<width>131</width>
110+
<height>20</height>
111+
</size>
112+
</property>
113+
</spacer>
114+
</item>
115+
<item>
116+
<widget class="QCheckBox" name="cboxEnabled" >
117+
<property name="text" >
118+
<string>Enable Copyright Label</string>
119+
</property>
120+
<property name="checked" >
121+
<bool>true</bool>
122+
</property>
123+
</widget>
124+
</item>
125+
</layout>
126+
</item>
43127
<item row="1" column="2" >
44128
<widget class="QTextEdit" name="txtCopyrightText" >
45129
<property name="html" >
46130
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
47131
p, li { white-space: pre-wrap; }
48-
&lt;/style>&lt;/head>&lt;body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">
49-
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;">&lt;span style=" font-size:14pt;">© QGIS 2006&lt;/span>&lt;/p>&lt;/body>&lt;/html></string>
50-
</property>
51-
</widget>
52-
</item>
53-
<item rowspan="4" row="0" column="1" >
54-
<widget class="Line" name="line1" >
55-
<property name="maximumSize" >
56-
<size>
57-
<width>2</width>
58-
<height>32767</height>
59-
</size>
60-
</property>
61-
<property name="frameShape" >
62-
<enum>QFrame::VLine</enum>
63-
</property>
64-
<property name="frameShadow" >
65-
<enum>QFrame::Sunken</enum>
66-
</property>
67-
<property name="orientation" >
68-
<enum>Qt::Vertical</enum>
69-
</property>
70-
</widget>
71-
</item>
72-
<item rowspan="4" row="0" column="0" >
73-
<widget class="QLabel" name="pixmapLabel2" >
74-
<property name="maximumSize" >
75-
<size>
76-
<width>150</width>
77-
<height>32767</height>
78-
</size>
79-
</property>
80-
<property name="pixmap" >
81-
<pixmap resource="copyright_plugin.qrc" >:/copyright.png</pixmap>
82-
</property>
83-
<property name="scaledContents" >
84-
<bool>true</bool>
132+
&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
133+
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-size:14pt;">© QGIS 2006&lt;/span>&lt;/p>&lt;/body>&lt;/html></string>
85134
</property>
86135
</widget>
87136
</item>
@@ -147,43 +196,42 @@ p, li { white-space: pre-wrap; }
147196
</item>
148197
</layout>
149198
</item>
150-
<item row="3" column="2" >
151-
<layout class="QHBoxLayout" >
152-
<property name="margin" >
153-
<number>0</number>
199+
<item rowspan="5" row="0" column="1" >
200+
<widget class="Line" name="line1" >
201+
<property name="maximumSize" >
202+
<size>
203+
<width>2</width>
204+
<height>32767</height>
205+
</size>
154206
</property>
155-
<property name="spacing" >
156-
<number>6</number>
207+
<property name="frameShape" >
208+
<enum>QFrame::VLine</enum>
157209
</property>
158-
<item>
159-
<spacer>
160-
<property name="orientation" >
161-
<enum>Qt::Horizontal</enum>
162-
</property>
163-
<property name="sizeType" >
164-
<enum>QSizePolicy::Expanding</enum>
165-
</property>
166-
<property name="sizeHint" >
167-
<size>
168-
<width>131</width>
169-
<height>20</height>
170-
</size>
171-
</property>
172-
</spacer>
173-
</item>
174-
<item>
175-
<widget class="QCheckBox" name="cboxEnabled" >
176-
<property name="text" >
177-
<string>Enable Copyright Label</string>
178-
</property>
179-
<property name="checked" >
180-
<bool>true</bool>
181-
</property>
182-
</widget>
183-
</item>
184-
</layout>
210+
<property name="frameShadow" >
211+
<enum>QFrame::Sunken</enum>
212+
</property>
213+
<property name="orientation" >
214+
<enum>Qt::Vertical</enum>
215+
</property>
216+
</widget>
217+
</item>
218+
<item rowspan="5" row="0" column="0" >
219+
<widget class="QLabel" name="pixmapLabel2" >
220+
<property name="maximumSize" >
221+
<size>
222+
<width>150</width>
223+
<height>32767</height>
224+
</size>
225+
</property>
226+
<property name="pixmap" >
227+
<pixmap resource="copyright_plugin.qrc" >:/copyright.png</pixmap>
228+
</property>
229+
<property name="scaledContents" >
230+
<bool>true</bool>
231+
</property>
232+
</widget>
185233
</item>
186-
<item row="4" column="0" colspan="3" >
234+
<item row="5" column="0" colspan="3" >
187235
<widget class="QDialogButtonBox" name="buttonBox" >
188236
<property name="orientation" >
189237
<enum>Qt::Horizontal</enum>
@@ -196,6 +244,13 @@ p, li { white-space: pre-wrap; }
196244
</layout>
197245
</widget>
198246
<layoutdefault spacing="6" margin="11" />
247+
<customwidgets>
248+
<customwidget>
249+
<class>QgsColorButton</class>
250+
<extends>QToolButton</extends>
251+
<header>qgscolorbutton.h</header>
252+
</customwidget>
253+
</customwidgets>
199254
<resources>
200255
<include location="copyright_plugin.qrc" />
201256
</resources>

0 commit comments

Comments
 (0)
Please sign in to comment.