~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/gui/symbology-ng/qgspenstylecombobox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "qgspenstylecombobox.h"
 
3
 
 
4
#include "qgsapplication.h"
 
5
 
 
6
#include <QList>
 
7
#include <QPair>
 
8
 
 
9
#include <QPainter>
 
10
#include <QPen>
 
11
 
 
12
QgsPenStyleComboBox::QgsPenStyleComboBox( QWidget* parent )
 
13
    : QComboBox( parent )
 
14
{
 
15
  QList < QPair<Qt::PenStyle, QString> > styles;
 
16
  styles << qMakePair( Qt::SolidLine, QString( "Solid Line" ) )
 
17
  << qMakePair( Qt::DashLine, QString( "Dash Line" ) )
 
18
  << qMakePair( Qt::DotLine, QString( "Dot Line" ) )
 
19
  << qMakePair( Qt::DashDotLine, QString( "Dash Dot Line" ) )
 
20
  << qMakePair( Qt::DashDotDotLine, QString( "Dash Dot Dot Line" ) )
 
21
  << qMakePair( Qt::NoPen, QString( "No Pen" ) );
 
22
 
 
23
  setIconSize( QSize( 32, 12 ) );
 
24
 
 
25
  for ( int i = 0; i < styles.count(); i++ )
 
26
  {
 
27
    Qt::PenStyle style = styles.at( i ).first;
 
28
    QString name = styles.at( i ).second;
 
29
    addItem( iconForPen( style ), name, QVariant( style ) );
 
30
  }
 
31
}
 
32
 
 
33
Qt::PenStyle QgsPenStyleComboBox::penStyle() const
 
34
{
 
35
  return ( Qt::PenStyle ) itemData( currentIndex() ).toInt();
 
36
}
 
37
 
 
38
void QgsPenStyleComboBox::setPenStyle( Qt::PenStyle style )
 
39
{
 
40
  int idx = findData( QVariant( style ) );
 
41
  setCurrentIndex( idx == -1 ? 0 : idx );
 
42
}
 
43
 
 
44
QIcon QgsPenStyleComboBox::iconForPen( Qt::PenStyle style )
 
45
{
 
46
  QPixmap pix( iconSize() );
 
47
  QPainter p;
 
48
  pix.fill( Qt::transparent );
 
49
 
 
50
  p.begin( &pix );
 
51
  QPen pen( style );
 
52
  pen.setWidth( 2 );
 
53
  p.setPen( pen );
 
54
  double mid = iconSize().height() / 2.0;
 
55
  p.drawLine( 0, mid, iconSize().width(), mid );
 
56
  p.end();
 
57
 
 
58
  return QIcon( pix );
 
59
}
 
60
 
 
61
 
 
62
/////////
 
63
// join
 
64
 
 
65
QgsPenJoinStyleComboBox::QgsPenJoinStyleComboBox( QWidget* parent )
 
66
    : QComboBox( parent )
 
67
{
 
68
  QString path = QgsApplication::defaultThemePath();
 
69
  addItem( QIcon( path + "/join_bevel.png" ), tr( "Bevel" ), QVariant( Qt::BevelJoin ) );
 
70
  addItem( QIcon( path + "/join_miter.png" ), tr( "Miter" ), QVariant( Qt::MiterJoin ) );
 
71
  addItem( QIcon( path + "/join_round.png" ), tr( "Round" ), QVariant( Qt::RoundJoin ) );
 
72
}
 
73
 
 
74
Qt::PenJoinStyle QgsPenJoinStyleComboBox::penJoinStyle() const
 
75
{
 
76
  return ( Qt::PenJoinStyle ) itemData( currentIndex() ).toInt();
 
77
}
 
78
 
 
79
void QgsPenJoinStyleComboBox::setPenJoinStyle( Qt::PenJoinStyle style )
 
80
{
 
81
  int idx = findData( QVariant( style ) );
 
82
  setCurrentIndex( idx == -1 ? 0 : idx );
 
83
}
 
84
 
 
85
 
 
86
/////////
 
87
// cap
 
88
 
 
89
QgsPenCapStyleComboBox::QgsPenCapStyleComboBox( QWidget* parent )
 
90
    : QComboBox( parent )
 
91
{
 
92
  QString path = QgsApplication::defaultThemePath();
 
93
  addItem( QIcon( path + "/cap_square.png" ), tr( "Square" ), QVariant( Qt::SquareCap ) );
 
94
  addItem( QIcon( path + "/cap_flat.png" ), tr( "Flat" ), QVariant( Qt::FlatCap ) );
 
95
  addItem( QIcon( path + "/cap_round.png" ), tr( "Round" ), QVariant( Qt::RoundCap ) );
 
96
}
 
97
 
 
98
Qt::PenCapStyle QgsPenCapStyleComboBox::penCapStyle() const
 
99
{
 
100
  return ( Qt::PenCapStyle ) itemData( currentIndex() ).toInt();
 
101
}
 
102
 
 
103
void QgsPenCapStyleComboBox::setPenCapStyle( Qt::PenCapStyle style )
 
104
{
 
105
  int idx = findData( QVariant( style ) );
 
106
  setCurrentIndex( idx == -1 ? 0 : idx );
 
107
}