2004-05-05 09:25:07 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2003 by Tim Sutton *
|
|
|
|
* tim@linfiniti.com *
|
|
|
|
* *
|
|
|
|
* This is a plugin generated from the QGIS plugin template *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
#include "plugingui.h"
|
|
|
|
|
|
|
|
//qt includes
|
2004-06-14 04:35:20 +00:00
|
|
|
#include <qapplication.h>
|
2004-05-10 22:45:22 +00:00
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qlabel.h>
|
2005-09-16 23:30:38 +00:00
|
|
|
#include <qglobal.h>
|
2005-11-19 23:35:22 +00:00
|
|
|
//Added by qt3to4:
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QPaintEvent>
|
2004-05-10 22:45:22 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <qspinbox.h>
|
2004-05-12 06:11:47 +00:00
|
|
|
#include <qslider.h>
|
2004-05-12 08:15:46 +00:00
|
|
|
#include <qtabwidget.h>
|
2005-11-19 23:35:22 +00:00
|
|
|
#include <q3combobox.h>
|
2004-05-16 21:04:46 +00:00
|
|
|
#include <qcheckbox.h>
|
2004-05-05 09:25:07 +00:00
|
|
|
//standard includes
|
2004-06-03 14:05:01 +00:00
|
|
|
#include <math.h>
|
2004-05-05 09:25:07 +00:00
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
QgsNorthArrowPluginGui::QgsNorthArrowPluginGui() : QgsNorthArrowPluginGuiBase()
|
2004-05-05 09:25:07 +00:00
|
|
|
{
|
2004-05-12 08:15:46 +00:00
|
|
|
//temporary hack until this is implemented
|
|
|
|
tabNorthArrowOptions->removePage( tabIcon );
|
2004-05-12 18:03:45 +00:00
|
|
|
rotatePixmap(0);
|
2004-05-05 09:25:07 +00:00
|
|
|
}
|
|
|
|
|
2005-11-19 23:35:22 +00:00
|
|
|
QgsNorthArrowPluginGui::QgsNorthArrowPluginGui( QWidget* parent , const char* name , bool modal , Qt::WFlags fl )
|
2005-04-24 00:22:35 +00:00
|
|
|
: QgsNorthArrowPluginGuiBase( parent, name, modal, fl )
|
2004-05-05 09:25:07 +00:00
|
|
|
{
|
2004-05-12 08:15:46 +00:00
|
|
|
//temporary hack until this is implemented
|
|
|
|
tabNorthArrowOptions->removePage( tabIcon );
|
2004-05-05 09:25:07 +00:00
|
|
|
}
|
2005-04-24 03:34:36 +00:00
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
QgsNorthArrowPluginGui::~QgsNorthArrowPluginGui()
|
2004-05-05 09:25:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::pbnOK_clicked()
|
2004-05-05 09:25:07 +00:00
|
|
|
{
|
2004-06-02 13:05:07 +00:00
|
|
|
// Hide the dialog
|
|
|
|
hide();
|
2004-05-05 09:25:07 +00:00
|
|
|
//close the dialog
|
2004-05-12 06:11:47 +00:00
|
|
|
emit rotationChanged(sliderRotation->value());
|
2005-07-03 00:18:14 +00:00
|
|
|
emit enableAutomatic(cboxAutomatic->isChecked());
|
2004-05-13 23:22:01 +00:00
|
|
|
emit changePlacement(cboPlacement->currentText());
|
2004-05-16 21:04:46 +00:00
|
|
|
emit enableNorthArrow(cboxShow->isChecked());
|
2005-07-03 00:18:14 +00:00
|
|
|
emit needToRefresh();
|
|
|
|
|
2004-05-05 09:25:07 +00:00
|
|
|
done(1);
|
2004-05-16 21:04:46 +00:00
|
|
|
}
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::pbnCancel_clicked()
|
2004-05-05 09:25:07 +00:00
|
|
|
{
|
2004-05-12 18:03:45 +00:00
|
|
|
close(1);
|
2004-05-05 09:25:07 +00:00
|
|
|
}
|
2004-05-10 22:45:22 +00:00
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::setRotation(int theInt)
|
2004-05-10 22:45:22 +00:00
|
|
|
{
|
|
|
|
rotatePixmap(theInt);
|
2004-05-12 18:03:45 +00:00
|
|
|
sliderRotation->setValue(theInt);
|
2004-05-10 22:45:22 +00:00
|
|
|
}
|
2004-05-12 18:03:45 +00:00
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::setPlacement(QString thePlacementQString)
|
2004-05-15 22:56:40 +00:00
|
|
|
{
|
|
|
|
cboPlacement->setCurrentText(tr(thePlacementQString));
|
|
|
|
}
|
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::setEnabled(bool theBool)
|
2004-05-16 21:30:40 +00:00
|
|
|
{
|
|
|
|
cboxShow->setChecked(theBool);
|
|
|
|
}
|
2004-05-16 21:04:46 +00:00
|
|
|
|
2005-07-03 00:18:14 +00:00
|
|
|
void QgsNorthArrowPluginGui::setAutomatic(bool theBool)
|
|
|
|
{
|
|
|
|
cboxAutomatic->setChecked(theBool);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QgsNorthArrowPluginGui::setAutomaticDisabled()
|
|
|
|
{
|
|
|
|
cboxAutomatic->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2004-05-10 22:45:22 +00:00
|
|
|
|
|
|
|
//overides function byt the same name created in .ui
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::spinSize_valueChanged( int theInt)
|
2004-05-10 22:45:22 +00:00
|
|
|
{
|
2004-05-12 18:03:45 +00:00
|
|
|
|
2004-05-10 22:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//overides function byt the same name created in .ui
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::sliderRotation_valueChanged( int theInt)
|
2004-05-10 22:45:22 +00:00
|
|
|
{
|
|
|
|
rotatePixmap(theInt);
|
|
|
|
}
|
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::rotatePixmap(int theRotationInt)
|
2004-05-10 22:45:22 +00:00
|
|
|
{
|
2004-05-12 18:03:45 +00:00
|
|
|
QPixmap myQPixmap;
|
2004-11-14 08:42:46 +00:00
|
|
|
#if defined(WIN32) || defined(Q_OS_MACX)
|
2004-06-14 04:35:20 +00:00
|
|
|
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
|
|
|
|
#endif
|
2004-05-12 18:03:45 +00:00
|
|
|
QString myFileNameQString = QString(PKGDATAPATH) + QString("/images/north_arrows/default.png");
|
|
|
|
//std::cout << "Trying to load " << myFileNameQString << std::cout;
|
|
|
|
if (myQPixmap.load(myFileNameQString))
|
|
|
|
{
|
|
|
|
QPixmap myPainterPixmap(myQPixmap.height(),myQPixmap.width());
|
|
|
|
myPainterPixmap.fill();
|
|
|
|
QPainter myQPainter;
|
|
|
|
myQPainter.begin(&myPainterPixmap);
|
|
|
|
|
|
|
|
double centerXDouble = myQPixmap.width()/2;
|
|
|
|
double centerYDouble = myQPixmap.height()/2;
|
|
|
|
//save the current canvas rotation
|
|
|
|
myQPainter.save();
|
|
|
|
//myQPainter.translate( (int)centerXDouble, (int)centerYDouble );
|
|
|
|
|
|
|
|
//rotate the canvas
|
|
|
|
myQPainter.rotate( theRotationInt );
|
|
|
|
//work out how to shift the image so that it appears in the center of the canvas
|
|
|
|
//(x cos a + y sin a - x, -x sin a + y cos a - y)
|
|
|
|
const double PI = 3.14159265358979323846;
|
|
|
|
double myRadiansDouble = (PI/180) * theRotationInt;
|
|
|
|
int xShift = static_cast<int>((
|
|
|
|
(centerXDouble * cos(myRadiansDouble)) +
|
|
|
|
(centerYDouble * sin(myRadiansDouble))
|
|
|
|
) - centerXDouble);
|
|
|
|
int yShift = static_cast<int>((
|
|
|
|
(-centerXDouble * sin(myRadiansDouble)) +
|
|
|
|
(centerYDouble * cos(myRadiansDouble))
|
|
|
|
) - centerYDouble);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//draw the pixmap in the proper position
|
|
|
|
myQPainter.drawPixmap(xShift,yShift,myQPixmap);
|
|
|
|
|
|
|
|
|
|
|
|
//unrotate the canvase again
|
|
|
|
myQPainter.restore();
|
|
|
|
myQPainter.end();
|
|
|
|
|
|
|
|
//determine the center of the canvas given that we will bitblt form the origin of the narrow
|
|
|
|
int myCenterXInt = static_cast<int>((pixmapLabel->width()-myQPixmap.width())/2);
|
|
|
|
int myCenterYInt = static_cast<int>((pixmapLabel->height()-myQPixmap.height())/2);
|
2005-09-16 23:30:38 +00:00
|
|
|
#if QT_VERSION < 0x040000
|
2004-05-12 18:03:45 +00:00
|
|
|
bitBlt ( pixmapLabel, myCenterXInt,myCenterYInt, &myPainterPixmap, 0, 0, -1 , -1, Qt::CopyROP, false);
|
2005-09-16 23:30:38 +00:00
|
|
|
#else
|
|
|
|
// TODO: Qt4 uses QPainter::drawPixmap instead; need to refactor
|
|
|
|
#endif
|
2004-05-12 18:03:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
//pixmapLabel1->setPixmap(myPainterPixmap);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QPixmap myPainterPixmap(200,200);
|
|
|
|
myPainterPixmap.fill();
|
|
|
|
QPainter myQPainter;
|
|
|
|
myQPainter.begin(&myPainterPixmap);
|
|
|
|
QFont myQFont("time", 18, QFont::Bold);
|
|
|
|
myQPainter.setFont(myQFont);
|
2004-05-15 22:56:40 +00:00
|
|
|
myQPainter.setPen(Qt::red);
|
2004-05-12 18:03:45 +00:00
|
|
|
myQPainter.drawText(10, 20, QString("Pixmap Not Found"));
|
|
|
|
myQPainter.end();
|
|
|
|
pixmapLabel->setPixmap(myPainterPixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when the widget needs to be updated.
|
|
|
|
//
|
2004-05-10 22:45:22 +00:00
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::paintEvent( QPaintEvent * thePaintEvent)
|
2004-05-12 18:03:45 +00:00
|
|
|
{
|
2004-05-16 21:04:46 +00:00
|
|
|
rotatePixmap(sliderRotation->value());
|
2004-05-12 18:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Called when the widget has been resized.
|
|
|
|
//
|
|
|
|
|
2005-04-24 00:22:35 +00:00
|
|
|
void QgsNorthArrowPluginGui::resizeEvent( QResizeEvent * theResizeEvent)
|
2004-05-12 18:03:45 +00:00
|
|
|
{
|
|
|
|
rotatePixmap(sliderRotation->value());
|
2004-05-10 22:45:22 +00:00
|
|
|
}
|