File indexing completed on 2024-04-28 15:14:03
0001 /*************************************************************************** 0002 File : ColorMapRenderer.cc 0003 Project : LabPlot 0004 -------------------------------------------------------------------- 0005 Copyright : (C) 2008 by Alexander Semke 0006 Email (use @ for *) : alexander.semke*web.de 0007 Description : colormap renderer class 0008 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * This program is free software; you can redistribute it and/or modify * 0014 * it under the terms of the GNU General Public License as published by * 0015 * the Free Software Foundation; either version 2 of the License, or * 0016 * (at your option) any later version. * 0017 * * 0018 * This program is distributed in the hope that it will be useful, * 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0021 * GNU General Public License for more details. * 0022 * * 0023 * You should have received a copy of the GNU General Public License * 0024 * along with this program; if not, write to the Free Software * 0025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0026 * Boston, MA 02110-1301 USA * 0027 * * 0028 ***************************************************************************/ 0029 #include "ColorMapRenderer.h" 0030 0031 #include <KDebug> 0032 #include <QFile> 0033 #include <QPainter> 0034 0035 QPixmap ColorMapRenderer::pixmap(const QString& fileName) { 0036 QFile file(fileName); 0037 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 0038 kDebug()<<"file "<<fileName<<" not found"<<endl; 0039 return QPixmap(); 0040 } 0041 0042 QColor rgb; 0043 QList<QColor> list_rgb; 0044 int red, green, blue; 0045 QTextStream in(&file); 0046 0047 while (!in.atEnd()) { 0048 in.readLine(); 0049 in >> red >> green >> blue; 0050 rgb.setRgb( red, green, blue ); 0051 list_rgb.append(rgb); 0052 // kDebug()<<red<<"\t"<<green<<"\t"<<blue<<endl; 0053 } 0054 0055 int height = list_rgb.size(); 0056 int width = 80; 0057 // kDebug()<<height<<"line read."<<endl; 0058 QPixmap pixmap(width, height); 0059 QPainter p( &pixmap ); 0060 for (int i = 0; i != height; ++i) { 0061 rgb = list_rgb.at(i); 0062 p.setPen( rgb ); 0063 p.drawLine( QPoint(0, height-i), QPoint(width, height-i) ); 0064 } 0065 0066 return pixmap; 0067 }