#include "Prefs.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ConfigReader.h" #include "Setup.h" #include "Prefs.h" #include "Datastore.h" #include "Extern.h" #include "AppControl.h" struct pagesize { char name[32]; int width; int height; }; bool lukko=false; pagesize pagesizes[]={"A1 594x841 mm",594,841,"A2 420x594 mm",420,594,"A3 297x420 mm",297,420,"A4 210x297 mm",210,297,"A5 148x210 mm",148,210, "B1 728x1030 mm",728,1030,"B2 515x728 mm",515,728,"B3 364x515 mm",364,515,"B4 257x364 mm",257,364,"B5 182x257 mm",182,257, "Executive 191x254 mm",191,254,"Folio 210x330 mm",210,330,"Legal 216x356 mm",216,356, "Letter 216x279 mm",216,279,"Custom...",0,0}; #define numofpages 15 setup::~setup() { delete Dialog; } setup::setup(QWidget *parent,config_file_reader *Pr,ApplicationControl *ap) :QObject(parent) { AppControl=ap; Prefs=Pr; Dialog=new Preferences(parent,NULL,0,0); Dialog->hide(); int i; // FONT TAB *********************** QSize size=QSize(20,14); bm1.resize(size); bm2.resize(size); bm3.resize(size); bm4.resize(size); bm5.resize(size); fontb=QFont(Prefs->String("BaseFont"),12,Prefs->Int("BaseFontWeight"),(bool)Prefs->Int("BaseFontItalic")); fonto=QFont(Prefs->String("OperatorFont"),12,Prefs->Int("OperatorFontWeight"),(bool)Prefs->Int("OperatorFontItalic")); fonti=QFont(Prefs->String("IndexFont"),12,Prefs->Int("IndexFontWeight"),(bool)Prefs->Int("IndexFontItalic")); fontf=QFont(Prefs->String("FunctionFont"),12,Prefs->Int("FunctionFontWeight"),(bool)Prefs->Int("FunctionFontItalic")); connect(Dialog->Color_B,SIGNAL(clicked()),this,SLOT(ColorB())); connect(Dialog->Color_I,SIGNAL(clicked()),this,SLOT(ColorI())); connect(Dialog->Color_F,SIGNAL(clicked()),this,SLOT(ColorF())); connect(Dialog->Color_O,SIGNAL(clicked()),this,SLOT(ColorO())); connect(Dialog->Color_S,SIGNAL(clicked()),this,SLOT(ColorS())); connect(Dialog->Set_B,SIGNAL(clicked()),this,SLOT(FontB())); connect(Dialog->Set_I,SIGNAL(clicked()),this,SLOT(FontI())); connect(Dialog->Set_F,SIGNAL(clicked()),this,SLOT(FontF())); connect(Dialog->Set_O,SIGNAL(clicked()),this,SLOT(FontO())); // PAGE TAB ********************************************** for (i=0;iPagesize->insertItem(pagesizes[i].name); connect(Dialog->Pagesize,SIGNAL(activated(int)),this,SLOT(PageSize(int))); connect(Dialog->Orientation,SIGNAL(activated(int)),this,SLOT(Orientation(int))); connect(Dialog->Grid,SIGNAL(activated(int)),this,SLOT(Grid(int))); connect(Dialog->Width,SIGNAL(valueChanged(int)),this,SLOT(Size(int))); connect(Dialog->Height,SIGNAL(valueChanged(int)),this,SLOT(Size(int))); Dialog->Width->setMaxValue(5000); Dialog->Height->setMaxValue(5000); connect(Dialog->Ok,SIGNAL(clicked()),this,SLOT(Ok())); connect(Dialog->Default,SIGNAL(clicked()),this,SLOT(Default())); } // PAGE SETUP void setup::Grid(int i) { Prefs->SetInt("GridSize",i*5); } void setup::Size(int i) { if (!lukko) { Dialog->Pagesize->setCurrentItem(numofpages-1); Dialog->Orientation->setEnabled(false); } lukko=false; } void setup::PageDisable() { if (Dialog->Pagesize->currentText()==QString("Custom...")) { Dialog->Orientation->setEnabled(false); } else { Dialog->Orientation->setEnabled(true); } } void setup::Orientation(int i) { PageSize(Dialog->Pagesize->currentItem()); } void setup::PageSize(int i) { PageDisable(); int w,h; if (Dialog->Orientation->currentItem()==0) { w=pagesizes[i].width; h=pagesizes[i].height; } else { h=pagesizes[i].width; w=pagesizes[i].height; } lukko=true; Dialog->Width->setValue(w); lukko=true; Dialog->Height->setValue(h); } // GENERAL void setup::Show() { Init(); Dialog->show(); } void setup::Init() { int i; Dialog->Family_B->setText(FontInfo(fontb)); Dialog->Family_I->setText(FontInfo(fonti)); Dialog->Family_F->setText(FontInfo(fontf)); Dialog->Family_O->setText(FontInfo(fonto)); co1=Prefs->Color("BaseFontColor"); co2=Prefs->Color("IndexFontColor"); co3=Prefs->Color("FunctionFontColor"); co4=Prefs->Color("OperatorFontColor"); co5=Prefs->Color("SymbolFontColor"); bm1.fill(co1); bm2.fill(co2); bm3.fill(co3); bm4.fill(co4); bm5.fill(co5); Dialog->Color_B->setPixmap(bm1); Dialog->Color_I->setPixmap(bm2); Dialog->Color_F->setPixmap(bm3); Dialog->Color_O->setPixmap(bm4); Dialog->Color_S->setPixmap(bm5); Dialog->Size_N->setValue(Prefs->Int("FontSizeNormal")); Dialog->Size_M->setValue(Prefs->Int("FontSizeSmall")); Dialog->Size_S->setValue(Prefs->Int("FontSizeExpSmall")); Dialog->CenterLine->setValue(Prefs->Int("BaseFontCenterLine")); // Page setup int w=Prefs->Int("PaperWidth"); int h=Prefs->Int("PaperHeight"); int p=numofpages-1; int o=0; // Portrait for (i=0;iOrientation->setCurrentItem(o); Dialog->Pagesize->setCurrentItem(p); lukko=true; Dialog->Width->setValue(w); lukko=true; Dialog->Height->setValue(h); Dialog->Grid->setCurrentItem(Prefs->Int("GridSize")/5); Dialog->Left->setValue(Prefs->Int("LeftMargin")); Dialog->Right->setValue(Prefs->Int("RightMargin")); Dialog->Top->setValue(Prefs->Int("TopMargin")); Dialog->Bottom->setValue(Prefs->Int("BottomMargin")); } void setup::Ok() { Prefs->SetInt("FontSizeNormal",Dialog->Size_N->value()); Prefs->SetInt("FontSizeSmall",Dialog->Size_M->value()); Prefs->SetInt("FontSizeIndex",Dialog->Size_M->value()); Prefs->SetInt("FontSizeExpSmall",Dialog->Size_S->value()); Prefs->SetInt("FontSizeIndexSmall",Dialog->Size_S->value()); Prefs->SetInt("BaseFontCenterLine",Dialog->CenterLine->value()); Prefs->SetInt("LeftMargin",Dialog->Left->value()); Prefs->SetInt("RightMargin",Dialog->Right->value()); Prefs->SetInt("TopMargin",Dialog->Top->value()); Prefs->SetInt("BottomMargin",Dialog->Bottom->value()); Prefs->SetInt("PaperWidth",Dialog->Width->value()); Prefs->SetInt("PaperHeight",Dialog->Height->value()); Dialog->hide(); DataStorage *msg=MESSAGE(MSG_CONFIGURATION); AppControl->PostMessage(msg,TO_APPCONTROL); AppControl->PostMessage(msg,TO_MAIN); } void setup::Default() { Ok(); Prefs->CreateFile(); } // FONTSETUP QString setup::FontInfo(QFont font) { QString fi=font.family(); if (font.italic()) fi.append(", italic, "); else fi.append(", "); QString no; no.setNum(font.weight()); fi.append(no); return(fi); } void setup::ColorB() { QColor c=QColorDialog::getColor(co1); if (c.isValid()) { bm1.fill(c); Dialog->Color_B->setPixmap(bm1); Prefs->SetColor("BaseFontColor",c); } } void setup::ColorI() { QColor c=QColorDialog::getColor(co2); if (c.isValid()) { bm2.fill(c); Dialog->Color_I->setPixmap(bm2); Prefs->SetColor("IndexFontColor",c); } } void setup::ColorF() { QColor c=QColorDialog::getColor(co3); if (c.isValid()) { bm3.fill(c); Dialog->Color_F->setPixmap(bm3); Prefs->SetColor("FunctionFontColor",c); } } void setup::ColorO() { QColor c=QColorDialog::getColor(co4); if (c.isValid()) { bm4.fill(c); Dialog->Color_O->setPixmap(bm4); Prefs->SetColor("OperatorFontColor",c); } } void setup::ColorS() { QColor c=QColorDialog::getColor(co5); if (c.isValid()) { bm5.fill(c); Dialog->Color_S->setPixmap(bm5); Prefs->SetColor("SymbolFontColor",c); } } void setup::FontB() { bool ok; QFont font=QFontDialog::getFont(&ok, fontb); if (ok) { fontb=font; Dialog->Family_B->setText(FontInfo(font)); QString fam=font.family(); int i=fam.find("["); if (i!=-1) fam.truncate(i-1); Prefs->SetString("BaseFont",fam); Prefs->SetInt("BaseFontItalic",font.italic()); Prefs->SetInt("BaseFontWeight",font.weight()); } } void setup::FontI() { bool ok; QFont font=QFontDialog::getFont(&ok, fonti); if (ok) { fonti=font; Dialog->Family_I->setText(FontInfo(font)); QString fam=font.family(); int i=fam.find("["); if (i!=-1) fam.truncate(i-1); Prefs->SetString("IndexFont",fam); Prefs->SetInt("IndexFontItalic",font.italic()); Prefs->SetInt("IndexFontWeight",font.weight()); } } void setup::FontF() { bool ok; QFont font=QFontDialog::getFont(&ok, fontf); if (ok) { fontf=font; Dialog->Family_F->setText(FontInfo(font)); QString fam=font.family(); int i=fam.find("["); if (i!=-1) fam.truncate(i-1); Prefs->SetString("FunctionFont",fam); Prefs->SetInt("FunctionFontItalic",font.italic()); Prefs->SetInt("FunctionFontWeight",font.weight()); } } void setup::FontO() { bool ok; QFont font=QFontDialog::getFont(&ok, fonto); if (ok) { fonto=font; Dialog->Family_O->setText(FontInfo(font)); QString fam=font.family(); int i=fam.find("["); if (i!=-1) fam.truncate(i-1); Prefs->SetString("OperatorFont",fam); Prefs->SetInt("OperatorFontItalic",font.italic()); Prefs->SetInt("OperatorFontWeight",font.weight()); } }