[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/marble
From: Inge Wallin <inge () lysator ! liu ! se>
Date: 2007-04-29 17:26:09
Message-ID: 1177867569.944154.23300.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 659196 by ingwa:
Cleaned class KAtlasWindRose
M +1 -0 ChangeLog
M +1 -2 src/CLEANING
M +121 -93 src/katlasmapscale.cpp
M +39 -24 src/katlasmapscale.h
--- trunk/playground/base/marble/ChangeLog #659195:659196
@@ -1,4 +1,5 @@
29.04.07 - ingwa
+ Cleaned katlasmapscale.{h,cpp}
Cleaned katlaswindrose.{h,cpp}
Cleaned katlascrosshair.{h,cpp}
Cleaned placemarkinfodialog.{h,cpp}
--- trunk/playground/base/marble/src/CLEANING #659195:659196
@@ -50,6 +50,7 @@
-------------------------------
katlascrosshair.h katlascrosshair.cpp
katlaswindrose.h katlaswindrose.cpp
+katlasmapscale.h katlasmapscale.cpp
DOING
@@ -77,8 +78,6 @@
tinywebbrowser.h tinywebbrowser.cpp
KdeMainWindow.h KdeMainWindow.cpp
-Items on the widget (QObjects):
-katlasmapscale.h katlasmapscale.cpp
Special: TexturePalette
This class must be cleaned by modifying marble/tools/palettegen
--- trunk/playground/base/marble/src/katlasmapscale.cpp #659195:659196
@@ -1,136 +1,164 @@
+#include "katlasmapscale.h"
+
+#include <QtCore/QDebug>
#include <QtGui/QPainter>
#include <QtGui/QColor>
-#include <QtCore/QDebug>
-#include "katlasmapscale.h"
-const double earthdiameter = 6378.0;
-KAtlasMapScale::KAtlasMapScale(QObject* parent) : QObject(parent) {
- m_unit = "km";
- m_scalebarwidth=250;
- m_scalebarheight=5;
+const double earthdiameter = 6378.0; // km
+
+KAtlasMapScale::KAtlasMapScale( QObject* parent )
+ : QObject(parent)
+{
+ m_unit = "km";
+ m_scalebarwidth = 250;
+ m_scalebarheight = 5;
+
#ifdef Q_OS_MACX
- m_font = QFont("Sans Serif",10);
+ m_font = QFont( "Sans Serif", 10 );
#else
- m_font = QFont("Sans Serif",8);
+ m_font = QFont( "Sans Serif", 8 );
#endif
- m_fontheight = QFontMetrics(m_font).ascent();
- m_leftmargin = QFontMetrics(m_font).boundingRect("0").width()/2;
- m_rightmargin = QFontMetrics(m_font).boundingRect("0000").width()/2;
+ m_fontheight = QFontMetrics( m_font ).ascent();
+ m_leftmargin = QFontMetrics( m_font ).boundingRect( "0" ).width() / 2;
+ m_rightmargin = QFontMetrics( m_font ).boundingRect( "0000" ).width() / 2;
- m_invscale = m_radius = 0;
- m_scalebarkm = 0.0;
- m_bestdivisor = m_pixelinterval = m_valueinterval = 0;
+ m_invscale = 0;
+ m_radius = 0;
+ m_scalebarkm = 0.0;
+ m_bestdivisor = 0;
+ m_pixelinterval = 0;
+ m_valueinterval = 0;
}
-QPixmap& KAtlasMapScale::drawScaleBarPixmap(int radius, int width){
- if ((radius == m_radius) && (m_scalebarwidth == width - m_leftmargin - \
m_rightmargin))
- return m_pixmap;
- m_radius = radius;
- m_pixmap = QPixmap(width + 20, m_fontheight + m_scalebarheight + 20);
- m_pixmap.fill(Qt::transparent);
+QPixmap& KAtlasMapScale::drawScaleBarPixmap( int radius, int width )
+{
+ if ( radius == m_radius
+ && m_scalebarwidth == width - m_leftmargin - m_rightmargin )
+ return m_pixmap;
+ m_radius = radius;
- QPainter painter(&m_pixmap);
+ m_pixmap = QPixmap( width + 20, m_fontheight + m_scalebarheight + 20 );
+ m_pixmap.fill( Qt::transparent );
+
+ QPainter painter( &m_pixmap );
- painter.setPen(QColor(Qt::black));
- painter.setBrush(QColor(192,192,192,192));
+ painter.setPen( QColor( Qt::black ) );
+ painter.setBrush( QColor( 192, 192, 192, 192 ) );
- painter.translate(.5, .5);
- painter.drawRect(0,0, m_pixmap.width()-1, m_pixmap.height()-1);
- painter.translate(4.5, 4.5);
+ painter.translate( 0.5, 0.5 );
+ painter.drawRect( 0, 0, m_pixmap.width() - 1, m_pixmap.height() - 1 );
+ painter.translate( 4.5, 4.5 );
- paintScaleBar(&painter, radius, width);
- return m_pixmap;
+ paintScaleBar( &painter, radius, width );
+ return m_pixmap;
}
-void KAtlasMapScale::paintScaleBar(QPainter* painter, int radius, int width){
- if ((radius == m_radius) && (width == m_scalebarwidth)) return;
- m_radius = radius;
+void KAtlasMapScale::paintScaleBar( QPainter* painter, int radius, int width )
+{
- m_scalebarwidth = width - m_leftmargin - m_rightmargin;
+ if ( radius == m_radius && width == m_scalebarwidth )
+ return;
- m_scalebarkm = (double)(m_scalebarwidth) * earthdiameter / (double)(radius);
+ m_radius = radius;
+ m_scalebarwidth = width - m_leftmargin - m_rightmargin;
- calcScaleBar();
+ m_scalebarkm = (double)(m_scalebarwidth) * earthdiameter / (double)(radius);
-// painter->setRenderHint(QPainter::TextAntialiasing, false);
- painter->setFont(m_font);
+ calcScaleBar();
- painter->setPen(QColor(Qt::darkGray));
- painter->setBrush(QColor(Qt::darkGray));
- painter->drawRect(m_leftmargin, m_fontheight+3, m_leftmargin + m_scalebarwidth + \
m_rightmargin,m_scalebarheight); + // \
painter->setRenderHint(QPainter::TextAntialiasing, false); + painter->setFont( \
m_font );
- painter->setPen(QColor(Qt::black));
- painter->setBrush(QColor(Qt::white));
- painter->drawRect(m_leftmargin,m_fontheight+3,m_bestdivisor*m_pixelinterval,m_scalebarheight);
+ painter->setPen( QColor( Qt::darkGray ) );
+ painter->setBrush( QColor( Qt::darkGray ) );
+ painter->drawRect( m_leftmargin, m_fontheight + 3,
+ m_leftmargin + m_scalebarwidth + m_rightmargin,
+ m_scalebarheight );
- painter->setBrush(QColor(Qt::black));
+ painter->setPen( QColor( Qt::black ) );
+ painter->setBrush( QColor( Qt::white ) );
+ painter->drawRect( m_leftmargin, m_fontheight + 3,
+ m_bestdivisor * m_pixelinterval, m_scalebarheight );
- QString intervalstr;
- int lastStringEnds=0;
- int currentStringBegin=0;
+ painter->setBrush( QColor( Qt::black ) );
+
+ QString intervalstr;
+ int lastStringEnds = 0;
+ int currentStringBegin = 0;
- for (int j = 0; j <= m_bestdivisor; j += 2){
- if (j < m_bestdivisor)
- painter->drawRect(m_leftmargin+j*m_pixelinterval,m_fontheight+3,m_pixelinterval-1,m_scalebarheight);
+ for ( int j = 0; j <= m_bestdivisor; j += 2 ) {
+ if ( j < m_bestdivisor )
+ painter->drawRect( m_leftmargin + j * m_pixelinterval,
+ m_fontheight + 3, m_pixelinterval - 1,
+ m_scalebarheight );
- intervalstr.setNum(j*m_valueinterval);
+ intervalstr.setNum( j * m_valueinterval );
- if (j == 0) {
- painter->drawText(0, m_fontheight, "0 " + m_unit);
- lastStringEnds=QFontMetrics(m_font).width("0 " + m_unit);
- continue;
- }
- currentStringBegin=m_leftmargin + \
j*m_pixelinterval-QFontMetrics(m_font).width(intervalstr)/2;
- if(lastStringEnds < currentStringBegin) {
- painter->drawText(currentStringBegin,m_fontheight,intervalstr);
- lastStringEnds=currentStringBegin+QFontMetrics(m_font).width(intervalstr);
- }
- }
+ if ( j == 0 ) {
+ painter->drawText( 0, m_fontheight, "0 " + m_unit );
+ lastStringEnds = QFontMetrics( m_font ).width( "0 " + m_unit );
+ continue;
+ }
+
+ currentStringBegin = ( m_leftmargin + j * m_pixelinterval
+ - QFontMetrics( m_font ).width( intervalstr ) / 2 );
+ if ( lastStringEnds < currentStringBegin ) {
+ painter->drawText( currentStringBegin, m_fontheight, intervalstr );
+ lastStringEnds = currentStringBegin + QFontMetrics( m_font ).width( \
intervalstr ); + }
+ }
}
-void KAtlasMapScale::calcScaleBar(){
- double magnitude = 1;
+void KAtlasMapScale::calcScaleBar()
+{
+ double magnitude = 1;
- // first we calculate the exact length of the whole area that is possibly
- // available scale bar available to the scalebar in kilometers
- int magvalue = (int)( m_scalebarkm );
+ // First we calculate the exact length of the whole area that is possibly
+ // available scale bar available to the scalebar in kilometers
+ int magvalue = (int)( m_scalebarkm );
- // we calculate the two most significant digits of the km-scalebar-length
- // and store them in magvalue
- while (magvalue >= 100) { magvalue /= 10; magnitude *= 10; }
+ // We calculate the two most significant digits of the km-scalebar-length
+ // and store them in magvalue.
+ while ( magvalue >= 100 ) {
+ magvalue /= 10;
+ magnitude *= 10;
+ }
- m_bestdivisor = 4;
- int bestmagvalue = 1;
+ m_bestdivisor = 4;
+ int bestmagvalue = 1;
- for (int i = 0; i < magvalue; i++){
- // We try to find the lowest divisor between 4 and 8 that
- // divides magvalue without remainder.
- for (int j = 4; j < 9; j++){
- if ((magvalue-i)%j == 0){
- // We store the very first result we find
- // and store m_bestdivisor and bestmagvalue
- // as a final result
- m_bestdivisor = j;
- bestmagvalue = magvalue - i;
- // Stop all for loops and end search
- i = magvalue;
- j = 9;
- }
- }
- // If magvalue doesn't divide through values between 4 and 8
- // (e.g. because it's a prime number) try again with
- // magvalue decreased by i.
- }
+ for ( int i = 0; i < magvalue; i++ ) {
+ // We try to find the lowest divisor between 4 and 8 that
+ // divides magvalue without remainder.
+ for ( int j = 4; j < 9; j++ ) {
+ if ( ( magvalue - i ) % j == 0 ) {
+ // We store the very first result we find and store
+ // m_bestdivisor and bestmagvalue as a final result.
+ m_bestdivisor = j;
+ bestmagvalue = magvalue - i;
- m_pixelinterval = (int)(m_scalebarwidth*(double)(bestmagvalue)/(double)(magvalue)/m_bestdivisor);
- m_valueinterval = (int)(bestmagvalue*magnitude/m_bestdivisor);
+ // Stop all for loops and end search
+ i = magvalue;
+ j = 9;
+ }
+ }
+
+ // If magvalue doesn't divide through values between 4 and 8
+ // (e.g. because it's a prime number) try again with magvalue
+ // decreased by i.
+ }
+
+ m_pixelinterval = (int)( m_scalebarwidth * (double)( bestmagvalue )
+ / (double)( magvalue ) / m_bestdivisor );
+ m_valueinterval = (int)( bestmagvalue * magnitude / m_bestdivisor );
}
+
#ifndef Q_OS_MACX
#include "katlasmapscale.moc"
#endif
--- trunk/playground/base/marble/src/katlasmapscale.h #659195:659196
@@ -9,53 +9,68 @@
//
// Copyright: See COPYING file that comes with this distribution
+
#ifndef KATLASMAPSCALE_H
#define KATLASMAPSCALE_H
+
#include <QtCore/QObject>
#include <QtGui/QPixmap>
#include <QtGui/QFont>
#include <QtGui/QFontMetrics>
+
/**
@author Torsten Rahn
*/
-class KAtlasMapScale : public QObject {
-Q_OBJECT
+class KAtlasMapScale : public QObject
+{
+ Q_OBJECT
-public:
- KAtlasMapScale(QObject *parent = 0);
+ public:
+ KAtlasMapScale(QObject *parent = 0);
- void setInvScale(int invscale){ m_invscale = invscale; }
- int invScale()const{ return m_invscale; }
+ int invScale() const { return m_invscale; }
+ void setInvScale( int invscale ) { m_invscale = invscale; }
+ int scaleBarHeight() const { return m_scalebarheight; }
+ void setScaleBarHeight( int scalebarheight ) {
+ m_scalebarheight = scalebarheight;
+ }
- void setScaleBarHeight(int scalebarheight){ m_scalebarheight = scalebarheight; }
- int scaleBarHeight()const{ return m_scalebarheight; }
+ int scaleBarWidth()const{ return m_scalebarwidth; }
- int scaleBarWidth()const{ return m_scalebarwidth; }
+ void paintScaleBar( QPainter*, int, int );
+ QPixmap& drawScaleBarPixmap( int, int );
- void paintScaleBar(QPainter*, int, int);
- QPixmap& drawScaleBarPixmap(int, int);
+ public slots:
+ void setScaleBarWidth( int scalebarwidth ) {
+ m_scalebarwidth = scalebarwidth;
+ }
-public slots:
+ private:
+ void calcScaleBar();
- void setScaleBarWidth(int scalebarwidth){ m_scalebarwidth = scalebarwidth; }
+ private:
+ QPixmap m_pixmap;
+ int m_invscale;
+ int m_radius;
+ int m_scalebarwidth;
+ int m_scalebarheight;
+ double m_scalebarkm;
-private:
- void calcScaleBar();
- QPixmap m_pixmap;
- int m_invscale, m_radius;
- int m_scalebarwidth, m_scalebarheight;
- double m_scalebarkm;
+ QFont m_font;
+ int m_leftmargin;
+ int m_rightmargin;
+ int m_fontheight;
+ int m_bestdivisor;
+ int m_pixelinterval;
+ int m_valueinterval;
- QFont m_font;
- int m_leftmargin, m_rightmargin, m_fontheight;
- int m_bestdivisor, m_pixelinterval, m_valueinterval;
-
- QString m_unit;
+ QString m_unit;
};
+
#endif // KATLASMAPSCALE_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic