Project

General

Profile

0002--Implemented-Settings-option-to-enable-disable-sen.patch

admin, 11/28/2008 06:35 PM

View differences:

src/qtui/settingspages/colorsettingspage.cpp
170 170
  ui.senderBG->setColor(QColor("white"));
171 171
  ui.senderBG->setEnabled(false);
172 172
  ui.senderUseBG->setChecked(false);
173
  ui.senderAutoColor->setChecked(true);  
173 174
  ui.newMsgMarkerFG->setColor(Qt::red);
174 175

  
175 176
  /*
......
348 349
  ui.timestampBG->setColor(QtUi::style()->format(UiStyle::Timestamp).background().color());
349 350
  ui.senderFG->setColor(QtUi::style()->format(UiStyle::Sender).foreground().color());
350 351
  ui.senderBG->setColor(QtUi::style()->format(UiStyle::Sender).background().color());
352
  settings["SenderAutoColor"] = s.value("senderAutoColor", QVariant(true));
353
  if (settings["SenderAutoColor"].toBool()) {
354
    ui.senderAutoColor->setChecked(true);
355
    ui.senderFrame->setEnabled(false);
356
  }
351 357
  settings["NewMsgMarkerFG"] = s.value("newMsgMarkerFG", QColor(Qt::red));
352 358
  ui.newMsgMarkerFG->setColor(settings["NewMsgMarkerFG"].value<QColor>());
353 359

  
......
460 466
  s.setValue("timestampUseBG", ui.timestampUseBG->isChecked());
461 467
  saveColor(UiStyle::Sender, ui.senderFG->color(), ui.senderBG->color(), ui.senderUseBG->isChecked());
462 468
  s.setValue("senderUseBG", ui.senderUseBG->isChecked());
469
  s.setValue("senderAutoColor", ui.senderAutoColor->isChecked());
470
  QtUi::style()->setSenderAutoColor(ui.senderAutoColor->isChecked());
463 471
  s.setValue("newMsgMarkerFG", ui.newMsgMarkerFG->color());
464 472

  
465 473
  /*
......
590 598
  if(QtUi::style()->format(UiStyle::Sender).foreground().color() != ui.senderFG->color()) return true;
591 599
  if(QtUi::style()->format(UiStyle::Sender).background().color() != ui.senderBG->color()) return true;
592 600
  if(settings["SenderUseBG"].toBool() != ui.senderUseBG->isChecked()) return true;
601
  if(settings["SenderAutoColor"].toBool() != ui.senderAutoColor->isChecked()) return true;
593 602
  if(settings["NewMsgMarkerFG"].value<QColor>() != ui.newMsgMarkerFG->color()) return true;
594 603

  
595 604
  /*
src/qtui/settingspages/colorsettingspage.ui
6 6
    <x>0</x>
7 7
    <y>0</y>
8 8
    <width>517</width>
9
    <height>532</height>
9
    <height>561</height>
10 10
   </rect>
11 11
  </property>
12 12
  <property name="sizePolicy" >
......
542 542
             </property>
543 543
            </widget>
544 544
           </item>
545
           <item row="6" column="1" >
546
            <spacer>
545
           <item row="6" column="2" >
546
            <spacer name="verticalSpacer_2" >
547 547
             <property name="orientation" >
548 548
              <enum>Qt::Vertical</enum>
549 549
             </property>
......
872 872
             </property>
873 873
            </widget>
874 874
           </item>
875
           <item row="8" column="1" >
876
            <spacer name="verticalSpacer" >
877
             <property name="orientation" >
878
              <enum>Qt::Vertical</enum>
879
             </property>
880
             <property name="sizeHint" stdset="0" >
881
              <size>
882
               <width>20</width>
883
               <height>40</height>
884
              </size>
885
             </property>
886
            </spacer>
887
           </item>
875 888
          </layout>
876 889
         </widget>
877 890
         <widget class="QWidget" name="Seite_2" >
878 891
          <attribute name="title" >
879 892
           <string>Message</string>
880 893
          </attribute>
881
          <layout class="QGridLayout" >
882
           <item row="0" column="1" >
894
          <layout class="QGridLayout" name="gridLayout_2" >
895
           <item row="0" column="2" >
883 896
            <widget class="QLabel" name="label_37" >
884 897
             <property name="text" >
885 898
              <string>Foreground</string>
......
889 902
             </property>
890 903
            </widget>
891 904
           </item>
892
           <item row="0" column="2" >
905
           <item row="0" column="3" >
893 906
            <widget class="QLabel" name="label_38" >
894 907
             <property name="text" >
895 908
              <string>Background</string>
......
899 912
             </property>
900 913
            </widget>
901 914
           </item>
902
           <item row="0" column="3" >
915
           <item row="0" column="4" >
903 916
            <widget class="QLabel" name="label_9" >
904 917
             <property name="text" >
905 918
              <string>Use BG</string>
......
916 929
             </property>
917 930
            </widget>
918 931
           </item>
919
           <item row="1" column="1" >
932
           <item row="1" column="2" >
920 933
            <widget class="ColorButton" name="timestampFG" >
921 934
             <property name="text" >
922 935
              <string/>
923 936
             </property>
924 937
            </widget>
925 938
           </item>
926
           <item row="1" column="2" >
939
           <item row="1" column="3" >
927 940
            <widget class="ColorButton" name="timestampBG" >
928 941
             <property name="enabled" >
929 942
              <bool>false</bool>
......
933 946
             </property>
934 947
            </widget>
935 948
           </item>
936
           <item row="1" column="3" >
949
           <item row="1" column="4" >
937 950
            <widget class="QCheckBox" name="timestampUseBG" >
938 951
             <property name="sizePolicy" >
939 952
              <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
......
949 962
             </property>
950 963
            </widget>
951 964
           </item>
952
           <item row="2" column="0" >
953
            <widget class="QLabel" name="label_28" >
954
             <property name="text" >
955
              <string>Sender:</string>
956
             </property>
957
            </widget>
958
           </item>
959
           <item row="2" column="1" >
960
            <widget class="ColorButton" name="senderFG" >
961
             <property name="text" >
962
              <string/>
963
             </property>
964
            </widget>
965
           </item>
966
           <item row="2" column="2" >
967
            <widget class="ColorButton" name="senderBG" >
968
             <property name="enabled" >
969
              <bool>false</bool>
970
             </property>
971
             <property name="text" >
972
              <string/>
973
             </property>
974
            </widget>
975
           </item>
976
           <item row="2" column="3" >
977
            <widget class="QCheckBox" name="senderUseBG" >
978
             <property name="sizePolicy" >
979
              <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
980
               <horstretch>0</horstretch>
981
               <verstretch>0</verstretch>
982
              </sizepolicy>
983
             </property>
984
             <property name="layoutDirection" >
985
              <enum>Qt::LeftToRight</enum>
986
             </property>
987
             <property name="text" >
988
              <string/>
989
             </property>
990
            </widget>
991
           </item>
992
           <item row="3" column="0" >
965
           <item row="5" column="0" >
993 966
            <widget class="QLabel" name="label_30" >
994 967
             <property name="text" >
995 968
              <string>Nick:</string>
996 969
             </property>
997 970
            </widget>
998 971
           </item>
999
           <item row="3" column="1" >
972
           <item row="5" column="2" >
1000 973
            <widget class="ColorButton" name="nickFG" >
1001 974
             <property name="text" >
1002 975
              <string/>
1003 976
             </property>
1004 977
            </widget>
1005 978
           </item>
1006
           <item row="3" column="2" >
979
           <item row="5" column="3" >
1007 980
            <widget class="ColorButton" name="nickBG" >
1008 981
             <property name="enabled" >
1009 982
              <bool>false</bool>
......
1013 986
             </property>
1014 987
            </widget>
1015 988
           </item>
1016
           <item row="3" column="3" >
989
           <item row="5" column="4" >
1017 990
            <widget class="QCheckBox" name="nickUseBG" >
1018 991
             <property name="sizePolicy" >
1019 992
              <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
......
1029 1002
             </property>
1030 1003
            </widget>
1031 1004
           </item>
1032
           <item row="4" column="0" >
1005
           <item row="6" column="0" >
1033 1006
            <widget class="QLabel" name="label_31" >
1034 1007
             <property name="text" >
1035 1008
              <string>Hostmask:</string>
1036 1009
             </property>
1037 1010
            </widget>
1038 1011
           </item>
1039
           <item row="4" column="1" >
1012
           <item row="6" column="2" >
1040 1013
            <widget class="ColorButton" name="hostmaskFG" >
1041 1014
             <property name="text" >
1042 1015
              <string/>
1043 1016
             </property>
1044 1017
            </widget>
1045 1018
           </item>
1046
           <item row="4" column="2" >
1019
           <item row="6" column="3" >
1047 1020
            <widget class="ColorButton" name="hostmaskBG" >
1048 1021
             <property name="enabled" >
1049 1022
              <bool>false</bool>
......
1053 1026
             </property>
1054 1027
            </widget>
1055 1028
           </item>
1056
           <item row="4" column="3" >
1029
           <item row="6" column="4" >
1057 1030
            <widget class="QCheckBox" name="hostmaskUseBG" >
1058 1031
             <property name="sizePolicy" >
1059 1032
              <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
......
1069 1042
             </property>
1070 1043
            </widget>
1071 1044
           </item>
1072
           <item row="5" column="0" >
1045
           <item row="7" column="0" >
1073 1046
            <widget class="QLabel" name="label_32" >
1074 1047
             <property name="text" >
1075 1048
              <string>Channelname:</string>
1076 1049
             </property>
1077 1050
            </widget>
1078 1051
           </item>
1079
           <item row="5" column="1" >
1052
           <item row="7" column="2" >
1080 1053
            <widget class="ColorButton" name="channelnameFG" >
1081 1054
             <property name="text" >
1082 1055
              <string/>
1083 1056
             </property>
1084 1057
            </widget>
1085 1058
           </item>
1086
           <item row="5" column="2" >
1059
           <item row="7" column="3" >
1087 1060
            <widget class="ColorButton" name="channelnameBG" >
1088 1061
             <property name="enabled" >
1089 1062
              <bool>false</bool>
......
1093 1066
             </property>
1094 1067
            </widget>
1095 1068
           </item>
1096
           <item row="5" column="3" >
1069
           <item row="7" column="4" >
1097 1070
            <widget class="QCheckBox" name="channelnameUseBG" >
1098 1071
             <property name="sizePolicy" >
1099 1072
              <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
......
1109 1082
             </property>
1110 1083
            </widget>
1111 1084
           </item>
1112
           <item row="6" column="0" >
1085
           <item row="8" column="0" >
1113 1086
            <widget class="QLabel" name="label_33" >
1114 1087
             <property name="text" >
1115 1088
              <string>Mode flags:</string>
1116 1089
             </property>
1117 1090
            </widget>
1118 1091
           </item>
1119
           <item row="6" column="1" >
1092
           <item row="8" column="2" >
1120 1093
            <widget class="ColorButton" name="modeFlagsFG" >
1121 1094
             <property name="text" >
1122 1095
              <string/>
1123 1096
             </property>
1124 1097
            </widget>
1125 1098
           </item>
1126
           <item row="6" column="2" >
1099
           <item row="8" column="3" >
1127 1100
            <widget class="ColorButton" name="modeFlagsBG" >
1128 1101
             <property name="enabled" >
1129 1102
              <bool>false</bool>
......
1133 1106
             </property>
1134 1107
            </widget>
1135 1108
           </item>
1136
           <item row="6" column="3" >
1109
           <item row="8" column="4" >
1137 1110
            <widget class="QCheckBox" name="modeFlagsUseBG" >
1138 1111
             <property name="sizePolicy" >
1139 1112
              <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
......
1149 1122
             </property>
1150 1123
            </widget>
1151 1124
           </item>
1152
           <item row="7" column="0" >
1125
           <item row="9" column="0" >
1153 1126
            <widget class="QLabel" name="label_34" >
1154 1127
             <property name="text" >
1155 1128
              <string>Url:</string>
1156 1129
             </property>
1157 1130
            </widget>
1158 1131
           </item>
1159
           <item row="7" column="1" >
1132
           <item row="9" column="2" >
1160 1133
            <widget class="ColorButton" name="urlFG" >
1161 1134
             <property name="text" >
1162 1135
              <string/>
1163 1136
             </property>
1164 1137
            </widget>
1165 1138
           </item>
1166
           <item row="7" column="2" >
1139
           <item row="9" column="3" >
1167 1140
            <widget class="ColorButton" name="urlBG" >
1168 1141
             <property name="enabled" >
1169 1142
              <bool>false</bool>
......
1173 1146
             </property>
1174 1147
            </widget>
1175 1148
           </item>
1176
           <item row="7" column="3" >
1149
           <item row="9" column="4" >
1177 1150
            <widget class="QCheckBox" name="urlUseBG" >
1178 1151
             <property name="sizePolicy" >
1179 1152
              <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
......
1189 1162
             </property>
1190 1163
            </widget>
1191 1164
           </item>
1192
           <item row="8" column="0" >
1165
           <item row="10" column="0" >
1193 1166
            <widget class="QLabel" name="label_11" >
1194 1167
             <property name="text" >
1195 1168
              <string>New Message Marker:</string>
1196 1169
             </property>
1197 1170
            </widget>
1198 1171
           </item>
1199
           <item row="8" column="1" >
1172
           <item row="10" column="2" >
1200 1173
            <widget class="ColorButton" name="newMsgMarkerFG" >
1201 1174
             <property name="text" >
1202 1175
              <string/>
1203 1176
             </property>
1204 1177
            </widget>
1205 1178
           </item>
1179
           <item row="3" column="0" >
1180
            <widget class="QLabel" name="label_28" >
1181
             <property name="text" >
1182
              <string>Sender:</string>
1183
             </property>
1184
            </widget>
1185
           </item>
1186
           <item row="4" column="0" >
1187
            <widget class="QLabel" name="label_12" >
1188
             <property name="text" >
1189
              <string>Sender auto coloring:</string>
1190
             </property>
1191
            </widget>
1192
           </item>
1193
           <item row="4" column="2" >
1194
            <widget class="QCheckBox" name="senderAutoColor" >
1195
             <property name="text" >
1196
              <string>Enable</string>
1197
             </property>
1198
            </widget>
1199
           </item>
1200
           <item row="3" column="2" colspan="3" >
1201
            <widget class="QFrame" name="senderFrame" >
1202
             <property name="frameShape" >
1203
              <enum>QFrame::NoFrame</enum>
1204
             </property>
1205
             <property name="frameShadow" >
1206
              <enum>QFrame::Plain</enum>
1207
             </property>
1208
             <layout class="QGridLayout" name="_2" >
1209
              <property name="leftMargin" >
1210
               <number>0</number>
1211
              </property>
1212
              <property name="topMargin" >
1213
               <number>0</number>
1214
              </property>
1215
              <property name="rightMargin" >
1216
               <number>18</number>
1217
              </property>
1218
              <property name="bottomMargin" >
1219
               <number>0</number>
1220
              </property>
1221
              <item row="0" column="0" >
1222
               <widget class="ColorButton" name="senderFG" >
1223
                <property name="text" >
1224
                 <string/>
1225
                </property>
1226
                <property name="flat" >
1227
                 <bool>false</bool>
1228
                </property>
1229
               </widget>
1230
              </item>
1231
              <item row="0" column="1" >
1232
               <widget class="ColorButton" name="senderBG" >
1233
                <property name="enabled" >
1234
                 <bool>false</bool>
1235
                </property>
1236
                <property name="text" >
1237
                 <string/>
1238
                </property>
1239
               </widget>
1240
              </item>
1241
              <item row="0" column="2" >
1242
               <widget class="QCheckBox" name="senderUseBG" >
1243
                <property name="sizePolicy" >
1244
                 <sizepolicy vsizetype="Fixed" hsizetype="Maximum" >
1245
                  <horstretch>0</horstretch>
1246
                  <verstretch>0</verstretch>
1247
                 </sizepolicy>
1248
                </property>
1249
                <property name="layoutDirection" >
1250
                 <enum>Qt::LeftToRight</enum>
1251
                </property>
1252
                <property name="text" >
1253
                 <string/>
1254
                </property>
1255
               </widget>
1256
              </item>
1257
             </layout>
1258
            </widget>
1259
           </item>
1206 1260
          </layout>
1261
          <zorder>label_37</zorder>
1262
          <zorder>label_38</zorder>
1263
          <zorder>label_9</zorder>
1264
          <zorder>label_29</zorder>
1265
          <zorder>timestampFG</zorder>
1266
          <zorder>timestampBG</zorder>
1267
          <zorder>timestampUseBG</zorder>
1268
          <zorder>label_30</zorder>
1269
          <zorder>nickFG</zorder>
1270
          <zorder>nickBG</zorder>
1271
          <zorder>nickUseBG</zorder>
1272
          <zorder>label_31</zorder>
1273
          <zorder>hostmaskFG</zorder>
1274
          <zorder>hostmaskBG</zorder>
1275
          <zorder>hostmaskUseBG</zorder>
1276
          <zorder>label_32</zorder>
1277
          <zorder>channelnameFG</zorder>
1278
          <zorder>channelnameBG</zorder>
1279
          <zorder>channelnameUseBG</zorder>
1280
          <zorder>label_33</zorder>
1281
          <zorder>modeFlagsFG</zorder>
1282
          <zorder>modeFlagsBG</zorder>
1283
          <zorder>modeFlagsUseBG</zorder>
1284
          <zorder>label_34</zorder>
1285
          <zorder>urlFG</zorder>
1286
          <zorder>urlBG</zorder>
1287
          <zorder>urlUseBG</zorder>
1288
          <zorder>label_11</zorder>
1289
          <zorder>newMsgMarkerFG</zorder>
1290
          <zorder>label_28</zorder>
1291
          <zorder>label_12</zorder>
1292
          <zorder>senderAutoColor</zorder>
1293
          <zorder>label_13</zorder>
1294
          <zorder>senderFrame</zorder>
1207 1295
         </widget>
1208 1296
        </widget>
1209 1297
       </item>
......
1219 1307
          <string>Preview:</string>
1220 1308
         </property>
1221 1309
         <layout class="QHBoxLayout" >
1310
          <property name="sizeConstraint" >
1311
           <enum>QLayout::SetDefaultConstraint</enum>
1312
          </property>
1313
          <property name="bottomMargin" >
1314
           <number>9</number>
1315
          </property>
1222 1316
          <item>
1223
           <widget class="QWidget" native="1" name="chatviewPreview" />
1317
           <widget class="QWidget" native="1" name="chatviewPreview" >
1318
            <zorder>tabWidget_2</zorder>
1319
           </widget>
1224 1320
          </item>
1225 1321
         </layout>
1226 1322
        </widget>
......
1972 2068
  </connection>
1973 2069
  <connection>
1974 2070
   <sender>senderUseBG</sender>
1975
   <signal>clicked(bool)</signal>
2071
   <signal>toggled(bool)</signal>
1976 2072
   <receiver>senderBG</receiver>
1977 2073
   <slot>setEnabled(bool)</slot>
1978 2074
   <hints>
......
2066 2162
    </hint>
2067 2163
   </hints>
2068 2164
  </connection>
2165
  <connection>
2166
   <sender>senderAutoColor</sender>
2167
   <signal>clicked(bool)</signal>
2168
   <receiver>senderFrame</receiver>
2169
   <slot>setDisabled(bool)</slot>
2170
   <hints>
2171
    <hint type="sourcelabel" >
2172
     <x>234</x>
2173
     <y>173</y>
2174
    </hint>
2175
    <hint type="destinationlabel" >
2176
     <x>327</x>
2177
     <y>143</y>
2178
    </hint>
2179
   </hints>
2180
  </connection>
2069 2181
 </connections>
2070 2182
</ui>
src/uisupport/uistyle.cpp
69 69
    _customFormats[type] = s.customFormat(type);
70 70
  }
71 71

  
72
  // Check for the sender auto coloring option
73
  _senderAutoColor = s.value("Flags/senderAutoColor", QVariant(true)).toBool();  
74

  
72 75
  // Now initialize the mapping between FormatCodes and FormatTypes...
73 76
  _formatCodes["%O"] = None;
74 77
  _formatCodes["%B"] = Bold;
......
148 151
  _cachedFontMetrics.clear();
149 152
}
150 153

  
154
void UiStyle::setSenderAutoColor( bool state ) {
155
  _senderAutoColor = state;
156
  UiStyleSettings s(_settingsKey);
157
  s.setValue("Flags/senderAutoColor", QVariant(state));
158
}
159

  
151 160
QTextCharFormat UiStyle::format(FormatType ftype, Settings::Mode mode) const {
152
  // TODO: implement setting for nick autocoloring and make a check for it here
153
  if ( (ftype & 0x00000fff) == Sender ) 
154
  {
155
    // If it is not enabled just set ftype to Sender and go on
161
  // Check for enabled sender auto coloring
162
  if ( (ftype & 0x00000fff) == Sender && !_senderAutoColor ) {
163
    // Just use the default sender style if auto coloring is disabled
164
    ftype = Sender;
156 165
  }
157 166

  
158 167
  if(mode == Settings::Custom && _customFormats.contains(ftype)) return _customFormats.value(ftype);
......
444 453
  quint16 hash;
445 454
  switch(type()) {
446 455
    case Message::Plain:
447
    // To produce random like but stable nick colorings some sort of hashing should work best.
448
    // In this case we just use the qt function qChecksum which produces a
449
    // CRC16 hash. This should be fast and 16 bits are more than enough.
450
    hash = qChecksum(_sender.toAscii().data(), _sender.toAscii().size());
451
    return (UiStyle::FormatType)((((hash % 21) + 1) << 24) + 0x200);
456
      // To produce random like but stable nick colorings some sort of hashing should work best.
457
      // In this case we just use the qt function qChecksum which produces a
458
      // CRC16 hash. This should be fast and 16 bits are more than enough.
459
      hash = qChecksum(_sender.toAscii().data(), _sender.toAscii().size());
460
      return (UiStyle::FormatType)((((hash % 21) + 1) << 24) + 0x200);
452 461
    case Message::Notice:
453 462
      return UiStyle::NoticeMsg; break;
454 463
    case Message::Server:
src/uisupport/uistyle.h
153 153
    QString mircToInternal(const QString &) const;
154 154

  
155 155
    void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/);
156
    void setSenderAutoColor(bool state);
156 157
    QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const;
157 158
    QTextCharFormat mergedFormat(quint32 formatType);
158 159
    QFontMetricsF *fontMetrics(quint32 formatType);
......
165 166
    QList<QTextLayout::FormatRange> toTextLayoutList(const FormatList &, int textLength);
166 167

  
167 168
  protected:
168

  
169
    bool _senderAutoColor;
169 170

  
170 171
  private:
171 172

  
172
-