1 /***************************************************************************
2 * Copyright (C) 2007 by Carsten Niehaus *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20 #include "legendwidget.h"
22 #include "kalziumschemetype.h"
23 #include "kalziumgradienttype.h"
24 #include "kalziumpainter.h"
31 #include <QGridLayout>
33 LegendWidget::LegendWidget( QWidget
*parent
)
39 void LegendWidget::setGradientType( KalziumGradientType
* type
)
41 kDebug() << "setGradientType";
42 m_gradientType
= type
;
45 void LegendWidget::setTableType( KalziumTableType
* type
)
51 void LegendWidget::setScheme( KalziumSchemeType
* type
)
57 void LegendWidget::setMode( KalziumPainter::MODE m
)
63 void LegendWidget::updateContent()
65 QList
< QPair
<QString
, QBrush
> > items
;
68 case KalziumPainter::NORMAL
://nothing to do here, all logic done in SOM
69 case KalziumPainter::SOM
:
71 if ( !m_scheme
) return;
73 QList
<legendPair
> items
;
74 if ( m_mode
== KalziumPainter::SOM
)
76 items
<< qMakePair( i18nc("one of the three states of matter (solid, liquid, vaporous or unknown)", "Solid" ), QBrush( Prefs::color_solid() ) );
77 items
<< qMakePair( i18nc("one of the three states of matter (solid, liquid, vaporous or unknown)", "Liquid" ), QBrush( Prefs::color_liquid() ) );
78 items
<< qMakePair( i18nc("one of the three states of matter (solid, liquid, vaporous or unknown)", "Vaporous" ), QBrush( Prefs::color_vapor() ) );
79 items
<< qMakePair( i18nc("one of the three states of matter (solid, liquid, vaporous or unknown)", "Unknown" ), QBrush( Qt::lightGray
) );
81 items
= m_scheme
->legendItems();
84 updateLegendItemLayout( items
);
88 case KalziumPainter::GRADIENT
:
90 QList
<legendPair
> items
;
92 if(m_gradientType
->logarithmicGradient())
93 gradientDesc
= i18nc("one of the two types of gradients available", "logarithmic");
95 gradientDesc
= i18nc("one of the two types of gradients available", "linear");
96 items
<< qMakePair( i18n( "Gradient: %1 (%2)" ,m_gradientType
->description(), gradientDesc
), QBrush() );
97 items
<< qMakePair( i18nc( "Minimum value of the gradient" , "Minimum: %1" , m_gradientType
->minValue() ), QBrush( m_gradientType
->firstColor() ) );
98 items
<< qMakePair( i18nc( "Maximum value of the gradient" , "Maximum: %1" , m_gradientType
->maxValue() ), QBrush( m_gradientType
->secondColor() ) );
100 updateLegendItemLayout( items
);
103 case KalziumPainter::TIME
:
110 void LegendWidget::updateLegendItemLayout( const QList
<legendPair
>& list
)
115 foreach ( LegendItem
* i
, m_legendItemList
) {
119 m_legendItemList
.clear();
121 QGridLayout
* layout
= new QGridLayout( this );
126 foreach ( const legendPair
&pair
, list
)
128 LegendItem
*item
= new LegendItem( pair
);
130 m_legendItemList
.append(item
);
132 layout
->addWidget(item
, x
, y
);
145 LegendItem::LegendItem(const QPair
<QString
, QBrush
>& pair
, QWidget
* parent
)
153 void LegendItem::paintEvent( QPaintEvent
* /* e */ )
157 QRect
rect(0, 0, height(), height() );
158 p
.fillRect( rect
, QBrush( m_pair
.second
) );
160 QRect
textRect( height() + 10 , 0 , width() - 10 , height() );
162 p
.drawText( textRect
, Qt::AlignLeft
| Qt::AlignVCenter
, m_pair
.first
);
166 #include "legendwidget.moc"