diff --git a/include/TECommon.h b/include/TECommon.h index fc29f921d..75e12cc23 100644 --- a/include/TECommon.h +++ b/include/TECommon.h @@ -13,6 +13,8 @@ #ifndef TECOMMON_H #define TECOMMON_H +#include + #ifndef BOOL typedef int BOOL; #endif @@ -76,4 +78,11 @@ inline BOOL operator != (ca a, ca b) return a.c != b.c || a.f != b.f || a.b != b.b || a.r != b.r; } +struct ColorEntry +{ + QColor color; + bool transparent; // if used on bg + bool bold; // if used on fg +}; + #endif // TECOMMON_H diff --git a/include/TEWidget.h b/include/TEWidget.h index 8d29e873a..097b658e3 100644 --- a/include/TEWidget.h +++ b/include/TEWidget.h @@ -22,13 +22,6 @@ #include "TECommon.h" -struct ColorEntry -{ - QColor color; - bool transparent; // if used on bg - bool bold; // if used on fg -}; - class TEWidget : public QFrame // a widget representing attributed text { Q_OBJECT diff --git a/include/kcmkonsole.h b/include/kcmkonsole.h index 254e5cb61..81fa9285d 100644 --- a/include/kcmkonsole.h +++ b/include/kcmkonsole.h @@ -5,6 +5,7 @@ #include #include +#include #include class PageFrame : public QWidget @@ -22,11 +23,22 @@ public: ~GeneralPage(); }; +class ColorTable : public QFrame +{ +public: + ColorTable(QWidget* parent); +protected: +//void paintEvent(QPaintEvent* e); +//void resizeEvent(QResizeEvent* e); +}; + class SchemaConfig : public PageFrame { Q_OBJECT public: SchemaConfig(QWidget* parent); ~SchemaConfig(); +private: + QListBox* lbox; }; class SessionConfig : public PageFrame diff --git a/include/main.h b/include/main.h index 1d2a01f09..951858924 100644 --- a/include/main.h +++ b/include/main.h @@ -25,16 +25,7 @@ #include "TEWidget.h" #include "TEmuVt102.h" #include "session.h" - -struct ColorSchema -{ - QString path; - int numb; - QString title; - QString imagepath; - int alignment; - ColorEntry table[TABLE_COLORS]; -}; +#include "schema.h" class TEDemo : public KTMainWindow { Q_OBJECT @@ -82,13 +73,9 @@ private: void setColorPixmaps(); void setColLin(int columns, int lines); - void addSchema(const ColorSchema* s); - void loadAllSchemas(); void setSchema(const char* path); void setSchema(const ColorSchema* s); void setFont(int fontno); - ColorSchema* readSchema(const char* path); - ColorSchema* defaultSchema(); void addSessionCommand(const char* path); void loadSessionCommands(); @@ -108,9 +95,6 @@ private: QPopupMenu* m_font; QPopupMenu* m_schema; QPopupMenu* m_size; -// - QIntDict numb2schema; - QDict path2schema; // bool b_menuvis; bool b_framevis; diff --git a/include/schema.h b/include/schema.h new file mode 100644 index 000000000..a0f04bf58 --- /dev/null +++ b/include/schema.h @@ -0,0 +1,29 @@ +#ifndef SCHEMA_include +#define SCHEMA_include + +#include +#include "TECommon.h" +#include +#include + +struct ColorSchema +{ +public: + QString path; + int numb; + QString title; + QString imagepath; + int alignment; + ColorEntry table[TABLE_COLORS]; +public: + static ColorSchema* readSchema(const char* path); + static ColorSchema* find(const char* path); + static ColorSchema* find(int num); + static ColorSchema* defaultSchema(); + static void loadAllSchemas(); + static int count(); +public: + void addSchema(); +}; + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 1883b95f0..724a5749f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,16 +37,16 @@ bin_PROGRAMS = konsole kcmkonsole lib_LTLIBRARIES = libkonsole.la -libkonsole_la_SOURCES = session.C TEWidget.C TEmuVt102.C TEScreen.C TEmulation.C TEShell.C +libkonsole_la_SOURCES = TEWidget.C TEmuVt102.C TEScreen.C TEmulation.C TEShell.C libkonsole_la_LDFLAGS = -version-info `expr $(VERSION) + $(SUBVERS)`:$(RELEASE):$(SUBVERS) # Which sources should be compiled for konsole. -konsole_SOURCES = main.C +konsole_SOURCES = main.C schema.C session.C konsole_LDADD = libkonsole.la $(LIB_KIMGIO) $(LIB_KDEUI) konsole_LDFLAGS = $(all_libraries) $(KDE_RPATH) -kcmkonsole_SOURCES = kcmkonsole.C +kcmkonsole_SOURCES = kcmkonsole.C schema.C kcmkonsole_LDADD = $(LIB_KIMGIO) $(LIB_KDEUI) kcmkonsole_LDFLAGS = $(all_libraries) $(KDE_RPATH) diff --git a/src/kcmkonsole.C b/src/kcmkonsole.C index 94c9780e3..db09b4909 100644 --- a/src/kcmkonsole.C +++ b/src/kcmkonsole.C @@ -12,9 +12,11 @@ */ #include "kcmkonsole.h" +#include "schema.h" #include "qlayout.h" #include "qpushbt.h" #include "qpixmap.h" +#include "qtableview.h" #include #include @@ -86,12 +88,52 @@ GeneralPage::~GeneralPage() //--| Schema configuration |---------------------------------------------------- + +ColorTable::ColorTable(QWidget* parent) : QFrame(parent) +{ + //setFrameStyle( QFrame::Panel | QFrame::Sunken ); + setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); + setBackgroundMode(PaletteBase); +} + +//void ColorTable::resizeEvent(QResizeEvent* e) +//{ +//} + +//void ColorTable::paintCell(QPainter* p, int row, int col) +//{ +//} + SchemaConfig::SchemaConfig(QWidget* parent) : PageFrame(parent) { - QLabel *bigWidget = new QLabel( "This is work in progress.", this ); + QLabel *bigWidget = new QLabel(this); //( "This is work in progress.", this ); bigWidget->setFrameStyle( QFrame::Panel | QFrame::Sunken ); bigWidget->setAlignment( AlignCenter ); bigWidget->setBackgroundMode(PaletteBase); + + QLabel *smlWidget = new QLabel( "This is work in progress.", bigWidget ); + smlWidget->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + smlWidget->setAlignment( AlignCenter ); + smlWidget->setBackgroundMode(PaletteBase); + + QGridLayout* topLayout = new QGridLayout( bigWidget, 2, 2, 5 ); + lbox = new QListBox(bigWidget); //FIXME: QT does not react on setFrameStyle + ColorTable* colorTableW = new ColorTable(bigWidget); + topLayout->setColStretch(0,4); + topLayout->setColStretch(1,2); + topLayout->setRowStretch(0,4); + topLayout->setRowStretch(1,1); + topLayout->addWidget( colorTableW, 0, 0 ); + topLayout->addWidget( lbox, 0, 1 ); + topLayout->addMultiCellWidget( smlWidget, 1,1, 0,1 ); + ColorSchema::loadAllSchemas(); + for (int i = 0; i < ColorSchema::count(); i++) + { ColorSchema* s = ColorSchema::find(i); +// assert( s ); + lbox->insertItem(s->title.data()); + } + topLayout->activate(); + Contents ( i18n( "Color Schema Management" @@ -140,6 +182,10 @@ KcmKonsole::KcmKonsole(int &argc, char **argv, const char *name) { if (runGUI()) { +// if (!pages || pages->contains("schemes")) + addPage(schemes = new SchemaConfig(dialog), + klocale->translate("&Color Schemes"), + "kcmkonsole-not-written-yet.html"); // if (!pages || pages->contains("general")) addPage(general = new GeneralPage(dialog), klocale->translate("&General"), @@ -148,10 +194,6 @@ KcmKonsole::KcmKonsole(int &argc, char **argv, const char *name) addPage(sessions = new SessionConfig(dialog), klocale->translate("&Sessions"), "kcmkonsole-not-written-yet.html"); -// if (!pages || pages->contains("schemes")) - addPage(schemes = new SchemaConfig(dialog), - klocale->translate("&Color Schemes"), - "kcmkonsole-not-written-yet.html"); if (schemes || sessions || general) dialog->show(); diff --git a/src/main.C b/src/main.C index 39803ff5f..eb673982d 100644 --- a/src/main.C +++ b/src/main.C @@ -70,8 +70,6 @@ static int session_no = 0; static QIntDict no2command; static int cmd_serial = 0; -static int schema_serial = 1; - TEDemo::TEDemo(const char* args[], int login_shell) : KTMainWindow() { se = NULL; @@ -101,7 +99,12 @@ TEDemo::TEDemo(const char* args[], int login_shell) : KTMainWindow() // load schema ///////////////////////////////////////////////////////////// curr_schema = 0; - loadAllSchemas(); + ColorSchema::loadAllSchemas(); + for (int i = 0; i < ColorSchema::count(); i++) + { ColorSchema* s = ColorSchema::find(i); + assert( s ); + m_schema->insertItem(s->title.data(),s->numb); + } //FIXME: we should build a complete session before running it. @@ -117,7 +120,7 @@ TEDemo::TEDemo(const char* args[], int login_shell) : KTMainWindow() TESession* initial = new TESession(this,te,args,"xterm",login_shell); initial->setFontNo(n_font); - initial->setSchemaNo(path2schema.find(s_schema)->numb); + initial->setSchemaNo(ColorSchema::find(s_schema)->numb); initial->setTitle(args[0]); // start first session ///////////////////////////////////////////////////// @@ -582,7 +585,7 @@ void TEDemo::newSession(int i) ColorSchema* schema = sch.isEmpty() ? (ColorSchema*)NULL - : path2schema.find(sch); + : ColorSchema::find(sch); int schmno = schema?schema->numb:se->schemaNo(); @@ -639,167 +642,7 @@ void TEDemo::doneSession(TESession* s, int status) } } -// --| Schema support |------------------------------------------------------- - -void TEDemo::addSchema(const ColorSchema* s) -{ - numb2schema.insert(s->numb,s); - path2schema.insert(s->path.data(),s); - m_schema->insertItem(s->title.data(),s->numb); -} - -void TEDemo::setSchema(int numb) -{ - ColorSchema* s = numb2schema.find(numb); - if (s) setSchema(s); -} - -void TEDemo::setSchema(const char* path) -{ - ColorSchema* s = path2schema.find(path); - if (s) setSchema(s); -} - -void TEDemo::setSchema(const ColorSchema* s) -{ - if (!s) return; - m_schema->setItemChecked(curr_schema,FALSE); - m_schema->setItemChecked(s->numb,TRUE); - s_schema = s->path; - curr_schema = s->numb; - pmPath = s->imagepath; - te->setColorTable(s->table); //FIXME: set twice here to work around a bug - pixmap_menu_activated(s->alignment); - te->setColorTable(s->table); - if (se) se->setSchemaNo(s->numb); -} - - -ColorSchema* TEDemo::readSchema(const char* path) -{ FILE* sysin = fopen(path,"r"); - char line[100]; int i; - - if (!sysin) return NULL; - // - ColorSchema* res = new ColorSchema; - res->path = path; - res->numb = schema_serial++; - for (i = 0; i < TABLE_COLORS; i++) - { - res->table[i].color = QColor(0,0,0); - res->table[i].transparent = 0; - res->table[i].bold = 0; - } - res->title = "[missing title]"; - res->imagepath = ""; - res->alignment = 1; - // - while (fscanf(sysin,"%80[^\n]\n",line) > 0) - { - if (strlen(line) > 5) - { - if (!strncmp(line,"title",5)) - { - res->title = line+6; - } - if (!strncmp(line,"image",5)) - { char rend[100], path[100]; int attr = 1; - if (sscanf(line,"image %s %s",rend,path) != 2) - continue; - if (!strcmp(rend,"tile" )) attr = 2; else - if (!strcmp(rend,"center")) attr = 3; else - if (!strcmp(rend,"full" )) attr = 4; else - continue; - res->imagepath = path; - res->alignment = attr; - } - if (!strncmp(line,"color",5)) - { int fi,cr,cg,cb,tr,bo; - if(sscanf(line,"color %d %d %d %d %d %d",&fi,&cr,&cg,&cb,&tr,&bo) != 6) - continue; - if (!(0 <= fi && fi <= TABLE_COLORS)) continue; - if (!(0 <= cr && cr <= 255 )) continue; - if (!(0 <= cg && cg <= 255 )) continue; - if (!(0 <= cb && cb <= 255 )) continue; - if (!(0 <= tr && tr <= 1 )) continue; - if (!(0 <= bo && bo <= 1 )) continue; - res->table[fi].color = QColor(cr,cg,cb); - res->table[fi].transparent = tr; - res->table[fi].bold = bo; - } - if (!strncmp(line,"sysfg",5)) - { int fi,tr,bo; - if(sscanf(line,"sysfg %d %d %d",&fi,&tr,&bo) != 3) - continue; - if (!(0 <= fi && fi <= TABLE_COLORS)) continue; - if (!(0 <= tr && tr <= 1 )) continue; - if (!(0 <= bo && bo <= 1 )) continue; - res->table[fi].color = kapp->textColor; - res->table[fi].transparent = tr; - res->table[fi].bold = bo; - } - if (!strncmp(line,"sysbg",5)) - { int fi,tr,bo; - if(sscanf(line,"sysbg %d %d %d",&fi,&tr,&bo) != 3) - continue; - if (!(0 <= fi && fi <= TABLE_COLORS)) continue; - if (!(0 <= tr && tr <= 1 )) continue; - if (!(0 <= bo && bo <= 1 )) continue; - res->table[fi].color = kapp->backgroundColor; - res->table[fi].transparent = tr; - res->table[fi].bold = bo; - } - } - } - fclose(sysin); - return res; -} - -static const ColorEntry default_table[TABLE_COLORS] = - // The following are almost IBM standard color codes, with some slight - // gamma correction for the dim colors to compensate for bright X screens. - // It contains the 8 ansiterm/xterm colors in 2 intensities. -{ - { QColor(0x00,0x00,0x00), 0, 0 }, { QColor(0xFF,0xFF,0xFF), 1, 0 }, // Dfore, Dback - { QColor(0x00,0x00,0x00), 0, 0 }, { QColor(0xB2,0x18,0x18), 0, 0 }, // Black, Red - { QColor(0x18,0xB2,0x18), 0, 0 }, { QColor(0xB2,0x68,0x18), 0, 0 }, // Green, Yellow - { QColor(0x18,0x18,0xB2), 0, 0 }, { QColor(0xB2,0x18,0xB2), 0, 0 }, // Blue, Magenta - { QColor(0x18,0xB2,0xB2), 0, 0 }, { QColor(0xB2,0xB2,0xB2), 0, 0 }, // Cyan, White - // intensive - { QColor(0x00,0x00,0x00), 0, 1 }, { QColor(0xFF,0xFF,0xFF), 1, 0 }, - { QColor(0x68,0x68,0x68), 0, 0 }, { QColor(0xFF,0x54,0x54), 0, 0 }, - { QColor(0x54,0xFF,0x54), 0, 0 }, { QColor(0xFF,0xFF,0x54), 0, 0 }, - { QColor(0x54,0x54,0xFF), 0, 0 }, { QColor(0xFF,0x54,0xFF), 0, 0 }, - { QColor(0x54,0xFF,0xFF), 0, 0 }, { QColor(0xFF,0xFF,0xFF), 0, 0 } -}; - -ColorSchema* TEDemo::defaultSchema() -{ - ColorSchema* res = new ColorSchema; - res->path = ""; - res->numb = 0; - res->title = "Konsole Default"; - res->imagepath = ""; // background pixmap - res->alignment = 1; // none - for (int i = 0; i < TABLE_COLORS; i++) - res->table[i] = default_table[i]; - return res; -} - -void TEDemo::loadAllSchemas() -{ - addSchema(defaultSchema()); - QString path = kapp->kde_datadir() + "/konsole"; - QDir d( path ); - if(!d.exists()) - return; - d.setFilter( QDir::Files | QDir::Readable ); - d.setNameFilter( "*.schema" ); - const QFileInfoList *list = d.entryInfoList(); - QFileInfoListIterator it( *list ); // create list iterator - for(QFileInfo *fi; (fi=it.current()); ++it ) - addSchema(readSchema(fi->filePath())); -} +// --| Session support |------------------------------------------------------- void TEDemo::addSessionCommand(const char* path) { @@ -832,6 +675,34 @@ void TEDemo::loadSessionCommands() addSessionCommand(fi->filePath()); } +// --| Schema support |------------------------------------------------------- + +void TEDemo::setSchema(int numb) +{ + ColorSchema* s = ColorSchema::find(numb); + if (s) setSchema(s); +} + +void TEDemo::setSchema(const char* path) +{ + ColorSchema* s = ColorSchema::find(path); + if (s) setSchema(s); +} + +void TEDemo::setSchema(const ColorSchema* s) +{ + if (!s) return; + m_schema->setItemChecked(curr_schema,FALSE); + m_schema->setItemChecked(s->numb,TRUE); + s_schema = s->path; + curr_schema = s->numb; + pmPath = s->imagepath; + te->setColorTable(s->table); //FIXME: set twice here to work around a bug + pixmap_menu_activated(s->alignment); + te->setColorTable(s->table); + if (se) se->setSchemaNo(s->numb); +} + /* --| main |---------------------------------------------------------------- */ static void usage() diff --git a/src/schema.C b/src/schema.C new file mode 100644 index 000000000..22fbb6510 --- /dev/null +++ b/src/schema.C @@ -0,0 +1,168 @@ +// [schema.C] + +/*! /class ColorSchema + + This is new stuff, so no docs yet. + + The identifier is the path. `numb' is guarantied to range from 0 to + count-1. Note when reloading the path can be assumed to still identify + a know schema, while the `numb' may vary. +*/ + +#include "schema.h" +#include +#include "kapp.h" +#include + +static int schema_serial = 0; //FIXME: remove,localize + +static QIntDict numb2schema; +static QDict path2schema; + +ColorSchema* ColorSchema::readSchema(const char* path) +{ FILE* sysin = fopen(path,"r"); + char line[100]; int i; + + if (!sysin) return NULL; + // + ColorSchema* res = new ColorSchema; + res->path = path; + res->numb = schema_serial++; + for (i = 0; i < TABLE_COLORS; i++) + { + res->table[i].color = QColor(0,0,0); + res->table[i].transparent = 0; + res->table[i].bold = 0; + } + res->title = "[missing title]"; + res->imagepath = ""; + res->alignment = 1; + // + while (fscanf(sysin,"%80[^\n]\n",line) > 0) + { + if (strlen(line) > 5) + { + if (!strncmp(line,"title",5)) + { + res->title = line+6; + } + if (!strncmp(line,"image",5)) + { char rend[100], path[100]; int attr = 1; + if (sscanf(line,"image %s %s",rend,path) != 2) + continue; + if (!strcmp(rend,"tile" )) attr = 2; else + if (!strcmp(rend,"center")) attr = 3; else + if (!strcmp(rend,"full" )) attr = 4; else + continue; + res->imagepath = path; + res->alignment = attr; + } + if (!strncmp(line,"color",5)) + { int fi,cr,cg,cb,tr,bo; + if(sscanf(line,"color %d %d %d %d %d %d",&fi,&cr,&cg,&cb,&tr,&bo) != 6) + continue; + if (!(0 <= fi && fi <= TABLE_COLORS)) continue; + if (!(0 <= cr && cr <= 255 )) continue; + if (!(0 <= cg && cg <= 255 )) continue; + if (!(0 <= cb && cb <= 255 )) continue; + if (!(0 <= tr && tr <= 1 )) continue; + if (!(0 <= bo && bo <= 1 )) continue; + res->table[fi].color = QColor(cr,cg,cb); + res->table[fi].transparent = tr; + res->table[fi].bold = bo; + } + if (!strncmp(line,"sysfg",5)) + { int fi,tr,bo; + if(sscanf(line,"sysfg %d %d %d",&fi,&tr,&bo) != 3) + continue; + if (!(0 <= fi && fi <= TABLE_COLORS)) continue; + if (!(0 <= tr && tr <= 1 )) continue; + if (!(0 <= bo && bo <= 1 )) continue; + res->table[fi].color = kapp->textColor; + res->table[fi].transparent = tr; + res->table[fi].bold = bo; + } + if (!strncmp(line,"sysbg",5)) + { int fi,tr,bo; + if(sscanf(line,"sysbg %d %d %d",&fi,&tr,&bo) != 3) + continue; + if (!(0 <= fi && fi <= TABLE_COLORS)) continue; + if (!(0 <= tr && tr <= 1 )) continue; + if (!(0 <= bo && bo <= 1 )) continue; + res->table[fi].color = kapp->backgroundColor; + res->table[fi].transparent = tr; + res->table[fi].bold = bo; + } + } + } + fclose(sysin); + return res; +} + +ColorSchema* ColorSchema::find(int numb) +{ + return numb2schema.find(numb); +} + +ColorSchema* ColorSchema::find(const char* path) +{ + return path2schema.find(path); +} + +int ColorSchema::count() +{ + return numb2schema.count(); +} + +void ColorSchema::addSchema() +{ + numb2schema.insert(numb,this); + path2schema.insert(path.data(),this); +} + +static const ColorEntry default_table[TABLE_COLORS] = + // The following are almost IBM standard color codes, with some slight + // gamma correction for the dim colors to compensate for bright X screens. + // It contains the 8 ansiterm/xterm colors in 2 intensities. +{ + { QColor(0x00,0x00,0x00), 0, 0 }, { QColor(0xFF,0xFF,0xFF), 1, 0 }, // Dfore, Dback + { QColor(0x00,0x00,0x00), 0, 0 }, { QColor(0xB2,0x18,0x18), 0, 0 }, // Black, Red + { QColor(0x18,0xB2,0x18), 0, 0 }, { QColor(0xB2,0x68,0x18), 0, 0 }, // Green, Yellow + { QColor(0x18,0x18,0xB2), 0, 0 }, { QColor(0xB2,0x18,0xB2), 0, 0 }, // Blue, Magenta + { QColor(0x18,0xB2,0xB2), 0, 0 }, { QColor(0xB2,0xB2,0xB2), 0, 0 }, // Cyan, White + // intensive + { QColor(0x00,0x00,0x00), 0, 1 }, { QColor(0xFF,0xFF,0xFF), 1, 0 }, + { QColor(0x68,0x68,0x68), 0, 0 }, { QColor(0xFF,0x54,0x54), 0, 0 }, + { QColor(0x54,0xFF,0x54), 0, 0 }, { QColor(0xFF,0xFF,0x54), 0, 0 }, + { QColor(0x54,0x54,0xFF), 0, 0 }, { QColor(0xFF,0x54,0xFF), 0, 0 }, + { QColor(0x54,0xFF,0xFF), 0, 0 }, { QColor(0xFF,0xFF,0xFF), 0, 0 } +}; + +ColorSchema* ColorSchema::defaultSchema() +{ + ColorSchema* res = new ColorSchema; + res->path = ""; + res->numb = 0; + res->title = "Konsole Default"; + res->imagepath = ""; // background pixmap + res->alignment = 1; // none + for (int i = 0; i < TABLE_COLORS; i++) + res->table[i] = default_table[i]; + return res; +} + +void ColorSchema::loadAllSchemas() +{ + defaultSchema()->addSchema(); + schema_serial = 1; + QString path = kapp->kde_datadir() + "/konsole"; + QDir d( path ); + if(!d.exists()) + return; + d.setFilter( QDir::Files | QDir::Readable ); + d.setNameFilter( "*.schema" ); + const QFileInfoList *list = d.entryInfoList(); + QFileInfoListIterator it( *list ); // create list iterator + for(QFileInfo *fi; (fi=it.current()); ++it ) + ColorSchema::readSchema(fi->filePath())->addSchema(); //FIXME: check for NULL +}