equal
deleted
inserted
replaced
102 QString * HWChatWidget::s_styleSheet = NULL; |
102 QString * HWChatWidget::s_styleSheet = NULL; |
103 QStringList * HWChatWidget::s_displayNone = NULL; |
103 QStringList * HWChatWidget::s_displayNone = NULL; |
104 bool HWChatWidget::s_isTimeStamped = true; |
104 bool HWChatWidget::s_isTimeStamped = true; |
105 QMutex HWChatWidget::s_styleSheetMutex; |
105 QMutex HWChatWidget::s_styleSheetMutex; |
106 |
106 |
107 QString & HWChatWidget::styleSheet() |
107 const QString & HWChatWidget::styleSheet() |
108 { |
108 { |
109 s_styleSheetMutex.lock(); |
109 s_styleSheetMutex.lock(); |
110 |
110 |
111 if (s_styleSheet != NULL) |
111 if (s_styleSheet != NULL) |
112 { |
112 { |
121 return *s_styleSheet; |
121 return *s_styleSheet; |
122 } |
122 } |
123 |
123 |
124 void HWChatWidget::setStyleSheet(const QString & styleSheet) |
124 void HWChatWidget::setStyleSheet(const QString & styleSheet) |
125 { |
125 { |
126 QString style = styleSheet; |
126 QString orgStyleSheet = styleSheet; |
|
127 QString style = QString(orgStyleSheet); |
127 |
128 |
128 // no stylesheet supplied, search for one or use default |
129 // no stylesheet supplied, search for one or use default |
129 if (style.isEmpty()) |
130 if (orgStyleSheet.isEmpty()) |
130 { |
131 { |
131 // load external stylesheet if there is any |
132 // load external stylesheet if there is any |
132 QFile extFile(HWDataManager::instance().findFileForRead("css/chat.css")); |
133 QFile extFile(HWDataManager::instance().findFileForRead("css/chat.css")); |
133 |
134 |
134 QFile resFile(":/res/css/chat.css"); |
135 QFile resFile(":/res/css/chat.css"); |
138 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
139 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
139 { |
140 { |
140 QTextStream in(&file); |
141 QTextStream in(&file); |
141 while (!in.atEnd()) |
142 while (!in.atEnd()) |
142 { |
143 { |
143 QString line = in.readLine(); |
144 style.append(in.readLine()+"\n"); |
144 if(!line.isEmpty()) |
|
145 style.append(line); |
|
146 } |
145 } |
|
146 orgStyleSheet = style; |
147 } |
147 } |
148 } |
148 } |
149 |
149 |
150 // let's parse display:none; ... |
150 // let's parse display:none; ... |
151 |
151 |
193 |
193 |
194 QStringList * oldDisplayNone = s_displayNone; |
194 QStringList * oldDisplayNone = s_displayNone; |
195 QString * oldStyleSheet = s_styleSheet; |
195 QString * oldStyleSheet = s_styleSheet; |
196 |
196 |
197 s_displayNone = new QStringList(victims); |
197 s_displayNone = new QStringList(victims); |
198 s_styleSheet = new QString(style); |
198 s_styleSheet = new QString(orgStyleSheet); |
199 |
199 |
200 if (oldDisplayNone != NULL) |
200 if (oldDisplayNone != NULL) |
201 delete oldDisplayNone; |
201 delete oldDisplayNone; |
202 |
202 |
203 if (oldStyleSheet != NULL) |
203 if (oldStyleSheet != NULL) |
769 } |
769 } |
770 } |
770 } |
771 |
771 |
772 void HWChatWidget::dropEvent(QDropEvent * event) |
772 void HWChatWidget::dropEvent(QDropEvent * event) |
773 { |
773 { |
774 QFile file( |
774 const QString path(event->mimeData()->urls()[0].toString()); |
775 event->mimeData()->urls()[0].toString().remove(QRegExp("^file://"))); |
775 QFile file(QString(path).remove(QRegExp("^file://"))); |
776 |
776 |
777 if (file.exists() && (file.open(QIODevice::ReadOnly | QIODevice::Text))) |
777 if (file.exists() && (file.open(QIODevice::ReadOnly | QIODevice::Text))) |
778 { |
778 { |
779 QString style; |
779 QString style; |
780 QTextStream in(&file); |
780 QTextStream in(&file); |
785 style.append(line); |
785 style.append(line); |
786 } |
786 } |
787 |
787 |
788 setStyleSheet(style); |
788 setStyleSheet(style); |
789 chatText->document()->setDefaultStyleSheet(*s_styleSheet); |
789 chatText->document()->setDefaultStyleSheet(*s_styleSheet); |
790 displayNotice(tr("Stylesheet replaced! Enter %1 if you want to use it in future, enter %2 to reset!").arg("/saveStyleSheet").arg("/discaredStyleSheet")); |
790 displayNotice(tr("Stylesheet imported from %1").arg(path)); |
|
791 displayNotice(tr("Enter %1 if you want to use the current styleSheet in future, enter %2 to reset!").arg("/saveStyleSheet").arg("/discaredStyleSheet")); |
791 |
792 |
792 event->acceptProposedAction(); |
793 event->acceptProposedAction(); |
793 } |
794 } |
|
795 else |
|
796 displayError(tr("Couldn't read %1").arg(event->mimeData()->urls()[0].toString())); |
794 } |
797 } |
795 |
798 |
796 |
799 |
797 void HWChatWidget::discardStyleSheet() |
800 void HWChatWidget::discardStyleSheet() |
798 { |
801 { |
809 |
812 |
810 QFile file(dest); |
813 QFile file(dest); |
811 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) |
814 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) |
812 { |
815 { |
813 QTextStream out(&file); |
816 QTextStream out(&file); |
814 out << *s_styleSheet; |
817 QStringList lines = s_styleSheet->split("\n", QString::KeepEmptyParts); |
|
818 |
|
819 // strip trailing empty lines |
|
820 while (lines.last().isEmpty()) |
|
821 lines.takeLast(); |
|
822 |
|
823 foreach (const QString & line, lines) |
|
824 { |
|
825 out << line << endl; |
|
826 } |
|
827 out << endl; |
815 file.close(); |
828 file.close(); |
816 displayNotice(tr("StyleSheet saved to %1").arg(dest)); |
829 displayNotice(tr("StyleSheet saved to %1").arg(dest)); |
817 } |
830 } |
818 else |
831 else |
819 displayError(tr("StyleSheet could NOT be saved to %1 !").arg(dest)); |
832 displayError(tr("Failed to save StyleSheet to %1").arg(dest)); |
820 } |
833 } |
821 |
834 |
822 |
835 |
823 bool HWChatWidget::parseCommand(const QString & line) |
836 bool HWChatWidget::parseCommand(const QString & line) |
824 { |
837 { |