[Kalzium] KDE/kdeedu/kalzium/src
Carsten Niehaus
cniehaus at gmx.de
Sun Jan 1 20:08:33 CET 2006
SVN commit 493170 by cniehaus:
* Implement the drawing of pixmaps
FIXME:The path is not yet correct!
FIXME:How should the activation take place? Pino: I need your help here!
CCMAIL:kalzium at kde.org
M +29 -1 kalziumdataobject.cpp
M +6 -1 kalziumdataobject.h
M +17 -2 kalziumpainter.cpp
M +2 -1 kalziumpainter.h
M +45 -0 kalziumschemetype.cpp
M +22 -0 kalziumschemetype.h
M +2 -4 simplecrystalviewer.cpp
--- trunk/KDE/kdeedu/kalzium/src/kalziumdataobject.cpp #493169:493170
@@ -52,9 +52,30 @@
reader.parse(source);
ElementList = parser->getElements();
-
+
// cache it
m_numOfElements = ElementList.count();
+
+ for ( int i = 0 ; i < m_numOfElements ; i++ )
+ {
+ QString setname = "school";
+
+// QString pathname = KGlobal::dirs()->findResourceDir( "data", "kalzium/data/" ) + "kalzium/iconsets/";
+
+//FIXME The path is of course wrong
+ QString pathname = "/home/kde4/svn/kdeedu/kalzium/data/iconsets/";
+
+ QString filename = pathname + setname + "/" + QString::number( i+1 ) + ".jpg";
+
+ QFile file( filename );
+ if ( file.exists() ) {
+ PixmapList << QPixmap( filename );
+ }
+ else {
+ PixmapList << QPixmap();
+ }
+ }
+
}
KalziumDataObject::~KalziumDataObject()
@@ -69,3 +90,10 @@
return ElementList[ number-1 ];
}
+QPixmap KalziumDataObject::pixmap( int number )
+{
+ // checking that we are requesting a valid element
+ if ( ( number <= 0 ) || ( number > m_numOfElements ) )
+ return 0;
+ return PixmapList[ number-1 ];
+}
--- trunk/KDE/kdeedu/kalzium/src/kalziumdataobject.h #493169:493170
@@ -21,6 +21,7 @@
***************************************************************************/
#include <element.h>
+#include <QPixmap>
/**
* @short This class contains all Element objects
@@ -58,7 +59,9 @@
* @param number the number of the Element which will be returned
*/
Element* element( int number );
-
+
+ QPixmap pixmap( int number );
+
/**
* Use this to get the number of elements we have. It is cached
* so you are strongly suggested to use this instead of hardcode
@@ -70,6 +73,8 @@
private:
KalziumDataObject();
~KalziumDataObject();
+
+ QList<QPixmap> PixmapList;
/**
* Caching the number of elements
--- trunk/KDE/kdeedu/kalzium/src/kalziumpainter.cpp #493169:493170
@@ -113,8 +113,9 @@
const QString symbol = el->dataAsString( ChemicalDataObject::symbol );
//kdDebug() << "ELEMENT: " << element << " RECT: " << rect << endl;
-bool grayedOut = true;
+ bool grayedOut = true;
+
switch ( m_mode )
{
case NORMAL:
@@ -211,6 +212,17 @@
m_painter->drawText( rect, Qt::AlignCenter, symbol );
break;
}
+ case PIXMAP:
+ {
+ QPixmap pixmap = KalziumDataObject::instance()->pixmap( el->dataAsString( ChemicalDataObject::atomicNumber ).toInt() );
+ QBrush c = QBrush( pixmap );
+ QColor textc = m_scheme->textColor( element );
+ m_painter->setPen( textc );
+
+ m_painter->fillRect( rect, c );
+ m_painter->drawRect( rect );
+ break;
+ }
}
}
@@ -351,7 +363,10 @@
void KalziumPainter::setMode( MODE m )
{
- m_mode = m;
+ //FIXME I still haven't found out how the MODE-setting should really work...
+ m_mode = KalziumPainter::PIXMAP;
+
+// m_mode = m;
}
KalziumPainter::MODE KalziumPainter::mode() const
--- trunk/KDE/kdeedu/kalzium/src/kalziumpainter.h #493169:493170
@@ -69,7 +69,8 @@
NORMAL = 0,
GRADIENT = 1,
SOM,
- SLIDE
+ SLIDE,
+ PIXMAP
};
/**
--- trunk/KDE/kdeedu/kalzium/src/kalziumschemetype.cpp #493169:493170
@@ -31,6 +31,7 @@
{
m_schemes << KalziumMonoColorSchemeType::instance();
m_schemes << KalziumBlocksSchemeType::instance();
+ m_schemes << KalziumIconicSchemeType::instance();
}
KalziumSchemeTypeFactory* KalziumSchemeTypeFactory::instance()
@@ -185,3 +186,47 @@
ll << qMakePair( i18n( "f-Block" ), Prefs::block_f() );
return ll;
}
+
+///ICONIC SCHEME///
+
+KalziumIconicSchemeType::KalziumIconicSchemeType()
+ : KalziumSchemeType()
+{
+}
+
+KalziumIconicSchemeType* KalziumIconicSchemeType::instance()
+{
+ static KalziumIconicSchemeType kbst;
+ return &kbst;
+}
+
+QByteArray KalziumIconicSchemeType::name() const
+{
+ return "Iconic";
+}
+
+QString KalziumIconicSchemeType::description() const
+{
+ return i18n( "Iconic" );
+}
+
+QGradient KalziumIconicSchemeType::elementGradient( int el, const QRect& elrect ) const
+{
+ QLinearGradient linearGrad( elrect.topLeft(), elrect.bottomRight() );
+
+ linearGrad.setColorAt( 0, QColor( Qt::yellow ) );
+ linearGrad.setColorAt( 1, QColor( Qt::green ) );
+ return linearGrad;
+}
+
+QColor KalziumIconicSchemeType::textColor( int el ) const
+{
+ Q_UNUSED( el );
+ return Qt::black;
+}
+
+legendList KalziumIconicSchemeType::legendItems() const
+{
+ legendList ll;
+ return ll;
+}
--- trunk/KDE/kdeedu/kalzium/src/kalziumschemetype.h #493169:493170
@@ -164,4 +164,26 @@
KalziumBlocksSchemeType();
};
+/**
+ * The scheme for iconic representation.
+ *
+ * @author Carsten Niehaus
+ */
+class KalziumIconicSchemeType : public KalziumSchemeType
+{
+ public:
+ static KalziumIconicSchemeType* instance();
+
+ QByteArray name() const;
+ QString description() const;
+
+ QGradient elementGradient( int el, const QRect& elrect ) const;
+ QColor textColor( int el ) const;
+
+ legendList legendItems() const;
+
+ private:
+ KalziumIconicSchemeType();
+};
+
#endif // KALZIUMSCHEMETYPE_H
--- trunk/KDE/kdeedu/kalzium/src/simplecrystalviewer.cpp #493169:493170
@@ -58,11 +58,9 @@
connect( combo, SIGNAL( activated( const QString& ) ), this, SLOT( slotCrystalChanged( const QString& ) ) );
- //FIXME The path is of course wrong
- m_basePath = KGlobal::dirs()->findResourceDir( "data", "kalzium/data/" ) + "kalzium/data/lattice";
+ //m_basePath = KGlobal::dirs()->findResourceDir( "data", "kalzium/data/" ) + "kalzium/data/lattice";
- kdDebug() << m_basePath << endl;
-
+//FIXME The path is of course wrong
m_basePath = "/home/kde4/svn/kdeedu/kalzium/data/lattice";
QDir dir( m_basePath );
More information about the Kalzium
mailing list