Skip to content

Commit

Permalink
Do for the copyright label what has just been done for the scale bar
Browse files Browse the repository at this point in the history
and north arrow (deal better with translated placement words).

Also tidy up scale bar and north arrow code a little bit.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5446 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed May 13, 2006
1 parent 5e4f62a commit d003d19
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 60 deletions.
64 changes: 34 additions & 30 deletions src/plugins/copyright_label/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ QgsCopyrightLabelPlugin::QgsCopyrightLabelPlugin(QgisApp * theQGisApp,
QgisPlugin(name_,description_,version_,type_),
qgisMainWindowPointer(theQGisApp),
qGisInterface(theQgisInterFace)
{}
{
mPlacementLabels << tr("Bottom Left") << tr("Top Left")
<< tr("Top Right") << tr("Bottom Right");
}

QgsCopyrightLabelPlugin::~QgsCopyrightLabelPlugin()
{}
Expand Down Expand Up @@ -110,7 +113,7 @@ void QgsCopyrightLabelPlugin::projectRead()
mQFont.setFamily(QgsProject::instance()->readEntry("CopyrightLabel","/FontName","Arial"));
mQFont.setPointSize(QgsProject::instance()->readNumEntry("CopyrightLabel","/FontSize",14));
mLabelQString = QgsProject::instance()->readEntry("CopyrightLabel","/Label","&copy; QGIS 2006");
mPlacement = QgsProject::instance()->readEntry("CopyrightLabel","/Placement","Bottom Right");
mPlacementIndex = QgsProject::instance()->readNumEntry("CopyrightLabel","/Placement",3);
mEnable = QgsProject::instance()->readBoolEntry("CopyrightLabel","/Enabled",true);
// todo - read & store state of font color
mLabelQColor = QColor(Qt::black);
Expand All @@ -133,10 +136,11 @@ void QgsCopyrightLabelPlugin::run()
connect(myPluginGui, SIGNAL(changeFont(QFont )), this, SLOT(setFont(QFont )));
connect(myPluginGui, SIGNAL(changeLabel(QString )), this, SLOT(setLabel(QString )));
connect(myPluginGui, SIGNAL(changeColor(QColor)), this, SLOT(setColor(QColor)));
connect(myPluginGui, SIGNAL(changePlacement(QString)), this, SLOT(setPlacement(QString)));
connect(myPluginGui, SIGNAL(changePlacement(int)), this, SLOT(setPlacement(int)));
connect(myPluginGui, SIGNAL(enableCopyrightLabel(bool)), this, SLOT(setEnable(bool)));
myPluginGui->setText(mLabelQString);
myPluginGui->setPlacement(mPlacement);
myPluginGui->setPlacementLabels(mPlacementLabels);
myPluginGui->setPlacement(mPlacementIndex);
myPluginGui->show();
}
//! Refresh the map display using the mapcanvas exported via the plugin interface
Expand Down Expand Up @@ -167,31 +171,31 @@ void QgsCopyrightLabelPlugin::renderLabel(QPainter * theQPainter)
int myYOffset = myHeight;
int myXOffset = myWidth;


//Determine placement of label from form combo box
if (mPlacement==tr("Bottom Left"))
{
//Define bottom left hand corner start point
myYOffset = myYOffset - (myQSimpleText.height()+5);
myXOffset = 5;
}
else if (mPlacement==tr("Top Left"))
{
//Define top left hand corner start point
myYOffset = 5;
myXOffset = 5;
}
else if (mPlacement==tr("Top Right"))
{
//Define top right hand corner start point
myYOffset = 5;
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
}
else // defaulting to bottom right
switch (mPlacementIndex)
{
//Define bottom right hand corner start point
myYOffset = myYOffset - (myQSimpleText.height()+5);
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
case 0: // Bottom Left
//Define bottom left hand corner start point
myYOffset = myYOffset - (myQSimpleText.height()+5);
myXOffset = 5;
break;
case 1: // Top left
//Define top left hand corner start point
myYOffset = 5;
myXOffset = 5;
break;
case 2: // Top Right
//Define top right hand corner start point
myYOffset = 5;
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
break;
case 3: // Bottom Right
//Define bottom right hand corner start point
myYOffset = myYOffset - (myQSimpleText.height()+5);
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
break;
default:
std::cerr << "Unknown placement index of " << mPlacementIndex << '\n';
}

//Paint label to canvas
Expand Down Expand Up @@ -243,10 +247,10 @@ void QgsCopyrightLabelPlugin::setColor(QColor theQColor)
}

//! set placement of copyright label
void QgsCopyrightLabelPlugin::setPlacement(QString theQString)
void QgsCopyrightLabelPlugin::setPlacement(int placementIndex)
{
mPlacement = theQString;
QgsProject::instance()->writeEntry("CopyrightLabel","/Placement", mPlacement);
mPlacementIndex = placementIndex;
QgsProject::instance()->writeEntry("CopyrightLabel","/Placement", mPlacementIndex);
refreshCanvas();
}

Expand Down
7 changes: 4 additions & 3 deletions src/plugins/copyright_label/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class QgsCopyrightLabelPlugin:public QObject, public QgisPlugin
//! change the copyright font colour
void setColor(QColor);
//! set copyright label placement
void setPlacement(QString);
void setPlacement(int);
//! set copyright label enabled
void setEnable(bool);

Expand All @@ -76,8 +76,9 @@ class QgsCopyrightLabelPlugin:public QObject, public QgisPlugin
QString mLabelQString;
//! This is the colour for the copyright label
QColor mLabelQColor;
//! Placement of the copyright label
QString mPlacement;
//! Placement of the copyright label - index and translated label names
int mPlacementIndex;
QStringList mPlacementLabels;
//! Copyright label enabled
bool mEnable;

Expand Down
12 changes: 9 additions & 3 deletions src/plugins/copyright_label/plugingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void QgsCopyrightLabelPluginGui::on_pbnOK_clicked()
emit changeFont(txtCopyrightText->currentFont());
emit changeLabel(txtCopyrightText->text());
emit changeColor(txtCopyrightText->color());
emit changePlacement(cboPlacement->currentText());
emit changePlacement(cboPlacement->currentIndex());
emit enableCopyrightLabel(cboxEnabled->isChecked());

done(1);
Expand All @@ -68,7 +68,13 @@ void QgsCopyrightLabelPluginGui::setText(QString theTextQString)
txtCopyrightText->setPlainText(theTextQString);
}

void QgsCopyrightLabelPluginGui::setPlacement(QString thePlacementQString)
void QgsCopyrightLabelPluginGui::setPlacementLabels(QStringList& labels)
{
cboPlacement->setCurrentText(tr(thePlacementQString));
cboPlacement->clear();
cboPlacement->addItems(labels);
}

void QgsCopyrightLabelPluginGui::setPlacement(int placementIndex)
{
cboPlacement->setCurrentIndex(placementIndex);
}
5 changes: 3 additions & 2 deletions src/plugins/copyright_label/plugingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Q_OBJECT;
QgsCopyrightLabelPluginGui( QWidget* parent = 0, Qt::WFlags fl = 0 );
~QgsCopyrightLabelPluginGui();
void setText(QString);
void setPlacement(QString);
void setPlacementLabels(QStringList&);
void setPlacement(int);

public slots:
void on_pbnOK_clicked();
Expand All @@ -44,7 +45,7 @@ public slots:
void changeFont(QFont);
void changeLabel(QString);
void changeColor(QColor);
void changePlacement(QString);
void changePlacement(int);
void enableCopyrightLabel(bool);

};
Expand Down
7 changes: 3 additions & 4 deletions src/plugins/north_arrow/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ QgsNorthArrowPlugin::QgsNorthArrowPlugin(QgisApp * theQGisApp,
QgisIface * theQgisInterFace):
QgisPlugin(name_,description_,version_,type_),
qgisMainWindowPointer(theQGisApp),
qGisInterface(theQgisInterFace),
mPlacementIndex(1)
qGisInterface(theQgisInterFace)
{
mRotationInt=0;
mAutomatic=true;
mPlacementLabels << tr("Bottom Left") << tr("Top Left") << tr("Top Right") << tr("Bottom Right");
mPlacementIndex = 0;
mPlacementLabels << tr("Bottom Left") << tr("Top Left")
<< tr("Top Right") << tr("Bottom Right");
}

QgsNorthArrowPlugin::~QgsNorthArrowPlugin()
Expand Down
10 changes: 0 additions & 10 deletions src/plugins/north_arrow/plugingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,6 @@ void QgsNorthArrowPluginGui::rotatePixmap(int theRotationInt)
}
}

// Called when the widget needs to be updated.
//
/*
void QgsNorthArrowPluginGui::paintEvent( QPaintEvent * thePaintEvent)
{
std::cerr<<__FILE__<<__LINE__<<'\n';
rotatePixmap(sliderRotation->value());
std::cerr<<__FILE__<<__LINE__<<'\n';
}
*/
//
// Called when the widget has been resized.
//
Expand Down
18 changes: 10 additions & 8 deletions src/plugins/scale_bar/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ QgsScaleBarPlugin::QgsScaleBarPlugin(QgisApp * theQGisApp,
qgisMainWindowPointer(theQGisApp),
qGisInterface(theQgisInterFace)
{
mPlacementLabels << tr("Top Left") << tr("Bottom Left") << tr("Top Right") << tr("Bottom Right");
mStyleLabels << tr("Tick Down") << tr("Tick Up") << tr("Bar") << tr("Box");
mPlacementLabels << tr("Bottom Left") << tr("Top Left")
<< tr("Top Right") << tr("Bottom Right");
mPlacementIndex = 1;
mStyleLabels << tr("Tick Down") << tr("Tick Up")
<< tr("Bar") << tr("Box");

mPreferredSize = 30;
mPlacementIndex = 0;
mStyleIndex = 0;
mEnabled = true;
mSnapping = true;
Expand Down Expand Up @@ -129,7 +131,7 @@ void QgsScaleBarPlugin::projectRead()

mPreferredSize = QgsProject::instance()->readNumEntry("ScaleBar","/PreferredSize",30);
mStyleIndex = QgsProject::instance()->readNumEntry("ScaleBar","/Style",0);
mPlacementIndex = QgsProject::instance()->readNumEntry("ScaleBar","/Placement",0);
mPlacementIndex = QgsProject::instance()->readNumEntry("ScaleBar","/Placement",2);
mEnabled = QgsProject::instance()->readBoolEntry("ScaleBar","/Enabled",true);
mSnapping = QgsProject::instance()->readBoolEntry("ScaleBar","/Snapping",true);
int myRedInt = QgsProject::instance()->readNumEntry("ScaleBar","/ColorRedPart",0);
Expand Down Expand Up @@ -301,13 +303,13 @@ void QgsScaleBarPlugin::renderScaleBar(QPainter * theQPainter)
int myOriginY=myMargin;
switch (mPlacementIndex)
{
case 0: // Top Left
case 0: // Bottom Left
myOriginX=myMargin;
myOriginY=myMargin;
myOriginY=myCanvasHeight - myMargin;
break;
case 1: // Bottom Left
case 1: // Top Left
myOriginX=myMargin;
myOriginY=myCanvasHeight - myMargin;
myOriginY=myMargin;
break;
case 2: // Top Right
myOriginX=myCanvasWidth - ((int) myTotalScaleBarWidth) - myMargin;
Expand Down

0 comments on commit d003d19

Please sign in to comment.