00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "GUIPref.h"
00021
00022 GUIPref* GUIPref::_instance = 0;
00023 GUIPref* GUIPref::Instance ()
00024 {
00025 if (_instance == 0)
00026 {
00027 _instance = new GUIPref;
00028 }
00029 return _instance;
00030 }
00031
00032 GUIPref::GUIPref()
00033 {
00034 DefaultTextColour.clear();
00035 DefaultBgColour.clear();
00036 InstituteTextColour.clear();
00037 InstituteBgColour.clear();
00038 ProgrammeTextColour.clear();
00039 ProgrammeBgColour.clear();
00040 ModuleTextColour.clear();
00041 ModuleBgColour.clear();
00042 FacultyTextColour.clear();
00043 FacultyBgColour.clear();
00044 DepartmentTextColour.clear();
00045 DepartmentBgColour.clear();
00046 StaffTextColour.clear();
00047 StaffBgColour.clear();
00048 RoomTextColour.clear();
00049 RoomBgColour.clear();
00050 ModLecAllocTextColour.clear();
00051 ModLecAllocBgColour.clear();
00052 TimeSlotTextColour.clear();
00053 TimeSlotBgColour.clear();
00054
00055 }
00056
00057 QColor * GUIPref::getColour(ColourType ct,int i)
00058 {
00059 switch (ct)
00060 {
00061 case CT_DEFAULT_TEXT:
00062 if (i >= DefaultTextColour.size())
00063 return new QColor("#000000");
00064 else
00065 return &DefaultTextColour[i];
00066 case CT_DEFAULT_BG:
00067 if (i >= DefaultBgColour.size())
00068 return new QColor("#FFFFFF");
00069 else
00070 return &DefaultBgColour[i];
00071 case CT_INSTITUTE_TEXT:
00072 if (i >= InstituteTextColour.size())
00073 return getColour(CT_DEFAULT_TEXT,i);
00074 else
00075 return &InstituteTextColour[i];
00076 case CT_INSTITUTE_BG:
00077 if (i >= InstituteBgColour.size())
00078 return getColour(CT_DEFAULT_BG,i);
00079 else
00080 return &InstituteBgColour[i];
00081 case CT_PROGRAMME_TEXT:
00082 if (i >= ProgrammeTextColour.size())
00083 return getColour(CT_DEFAULT_TEXT,i);
00084 else
00085 return &ProgrammeTextColour[i];
00086 case CT_PROGRAMME_BG:
00087 if (i >= ProgrammeBgColour.size())
00088 return getColour(CT_DEFAULT_BG,i);
00089 else
00090 return &ProgrammeBgColour[i];
00091 case CT_MODULE_TEXT:
00092 if (i >= ModuleTextColour.size())
00093 return getColour(CT_DEFAULT_TEXT,i);
00094 else
00095 return &ModuleTextColour[i];
00096 case CT_MODULE_BG:
00097 if (i >= ModuleBgColour.size())
00098 return getColour(CT_DEFAULT_BG,i);
00099 else
00100 return &ModuleBgColour[i];
00101 case CT_FACULTY_TEXT:
00102 if (i >= FacultyTextColour.size())
00103 return getColour(CT_DEFAULT_TEXT,i);
00104 else
00105 return &FacultyTextColour[i];
00106 case CT_FACULTY_BG:
00107 if (i >= FacultyBgColour.size())
00108 return getColour(CT_DEFAULT_BG,i);
00109 else
00110 return &FacultyBgColour[i];
00111 case CT_DEPARTMENT_TEXT:
00112 if (i >= DepartmentTextColour.size())
00113 return getColour(CT_DEFAULT_TEXT,i);
00114 else
00115 return &DepartmentTextColour[i];
00116 case CT_DEPARTMENT_BG:
00117 if (i >= DepartmentBgColour.size())
00118 return getColour(CT_DEFAULT_BG,i);
00119 else
00120 return &DepartmentBgColour[i];
00121 case CT_STAFF_TEXT:
00122 if (i >= StaffTextColour.size())
00123 return getColour(CT_DEFAULT_TEXT,i);
00124 else
00125 return &StaffTextColour[i];
00126 case CT_STAFF_BG:
00127 if (i >= StaffBgColour.size())
00128 return getColour(CT_DEFAULT_BG,i);
00129 else
00130 return &StaffBgColour[i];
00131 case CT_ROOM_TEXT:
00132 if (i >= RoomTextColour.size())
00133 return getColour(CT_DEFAULT_TEXT,i);
00134 else
00135 return &RoomTextColour[i];
00136 case CT_ROOM_BG:
00137 if (i >= RoomBgColour.size())
00138 return getColour(CT_DEFAULT_BG,i);
00139 else
00140 return &RoomBgColour[i];
00141 case CT_MOD_LEC_ALLOC_TEXT:
00142 if (i >= ModLecAllocTextColour.size())
00143 return getColour(CT_DEFAULT_TEXT,i);
00144 else
00145 return &ModLecAllocTextColour[i];
00146 case CT_MOD_LEC_ALLOC_BG:
00147 if (i >= ModLecAllocBgColour.size())
00148 return getColour(CT_DEFAULT_BG,i);
00149 else
00150 return &ModLecAllocBgColour[i];
00151 case CT_TIMESLOT_TEXT:
00152 if (i >= TimeSlotTextColour.size())
00153 return getColour(CT_DEFAULT_TEXT,i);
00154 else
00155 return &TimeSlotTextColour[i];
00156 case CT_TIMESLOT_BG:
00157 if (i >= TimeSlotBgColour.size())
00158 return getColour(CT_DEFAULT_BG,i);
00159 else
00160 return &TimeSlotBgColour[i];
00161 }
00162 }
00163
00164 void GUIPref::readColourArray(QSettings &settings, QList<QColor> &SettingList, QString ArrayName, QString SettingName)
00165 {
00166 QVariant value;
00167 int size = settings.beginReadArray(ArrayName);
00168 for (int i = 0; i < size; ++i)
00169 {
00170 settings.setArrayIndex(i);
00171 value = settings.value(SettingName);
00172 if (value.toString().startsWith('#'))
00173 SettingList.append(QColor(value.toString()));
00174 else
00175 SettingList.append(QColor(value.toUInt()));
00176 }
00177 settings.endArray();
00178 }
00179
00180 void GUIPref::readColours()
00181 {
00182 QSettings settings;
00183 settings.beginGroup("GUI");
00184 readColourArray(settings, DefaultTextColour, "DefaultColour", "TextColour");
00185 readColourArray(settings, DefaultBgColour, "DefaultColour", "BackgroundColour");
00186 readColourArray(settings, InstituteTextColour, "InstituteColour", "TextColour");
00187 readColourArray(settings, InstituteBgColour, "InstituteColour", "BackgroundColour");
00188 readColourArray(settings, ProgrammeTextColour, "ProgrammeColour", "TextColour");
00189 readColourArray(settings, ProgrammeBgColour, "ProgrammeColour", "BackgroundColour");
00190 readColourArray(settings, ModuleTextColour, "ModuleColour", "TextColour");
00191 readColourArray(settings, ModuleBgColour, "ModuleColour", "BackgroundColour");
00192 readColourArray(settings, FacultyTextColour, "FacultyColour", "TextColour");
00193 readColourArray(settings, FacultyBgColour, "FacultyColour", "BackgroundColour");
00194 readColourArray(settings, DepartmentTextColour, "DepartmentColour", "TextColour");
00195 readColourArray(settings, DepartmentBgColour, "DepartmentColour", "BackgroundColour");
00196 readColourArray(settings, StaffTextColour, "StaffColour", "TextColour");
00197 readColourArray(settings, StaffBgColour, "StaffColour", "BackgroundColour");
00198 readColourArray(settings, RoomTextColour, "RoomColour", "TextColour");
00199 readColourArray(settings, RoomBgColour, "RoomColour", "BackgroundColour");
00200 readColourArray(settings, ModLecAllocTextColour,"ModLecAllocColour","TextColour");
00201 readColourArray(settings, ModLecAllocBgColour, "ModLecAllocColour","BackgroundColour");
00202 readColourArray(settings, TimeSlotTextColour, "TimeSlotColour" ,"TextColour");
00203 readColourArray(settings, TimeSlotBgColour, "TimeSlotColour" ,"BackgroundColour");
00204 settings.endGroup();
00205 }
00206
00207 void GUIPref::writeColours()
00208 {
00209 QSettings settings;
00210 settings.beginGroup("GUI");
00211 settings.beginWriteArray("defaultColour");
00212 settings.setArrayIndex(0);
00213 settings.setValue("TextColour", QColor(205,55,0).rgb());
00214 settings.setValue("BackgroundColour", QColor(255,239,219).rgb());
00215 settings.setArrayIndex(1);
00216 settings.setValue("TextColour", QColor(139,37,0).rgb());
00217 settings.setValue("BackgroundColour", QColor(238,223,204).rgb());
00218 settings.endArray();
00219 settings.endGroup();
00220 }