24 #ifndef KLFMAINWIN_P_H 25 #define KLFMAINWIN_P_H 38 #include <QImageReader> 41 #include <QMessageBox> 50 #include <ui_klfaboutdialog.h> 51 #include <ui_klfwhatsnewdialog.h> 71 f.
open(QIODevice::ReadOnly);
74 klfDbg(
"read from file="<<fn<<
" the HTML code=\n"<<html ) ;
81 klfDbg(
"new HTML is:\n"<<html ) ;
84 html.
replace(
"<!--KLF_VERSION-->", KLF_VERSION_STRING);
100 void linkActivated(
const QUrl&);
104 u =
new Ui::KLFAboutDialog;
107 connect(u->txtDisplay, SIGNAL(anchorClicked(
const QUrl&)),
108 this, SIGNAL(linkActivated(
const QUrl&)));
117 setStyleSheet(styleSheet());
121 Ui::KLFAboutDialog *u;
130 void linkActivated(
const QUrl&);
136 u =
new Ui::KLFWhatsNewDialog;
139 connect(u->txtDisplay, SIGNAL(anchorClicked(
const QUrl&)),
140 this, SIGNAL(linkActivated(
const QUrl&)));
149 setStyleSheet(styleSheet());
153 Ui::KLFWhatsNewDialog *u;
164 :
QLabel(mainwin, Qt::Window|Qt::FramelessWindowHint|Qt::CustomizeWindowHint|
165 Qt::WindowStaysOnTopHint|Qt::X11BypassWindowManagerHint)
167 setObjectName(
"KLFMainWinPopup");
168 setFocusPolicy(Qt::NoFocus);
171 setGeometry(
QRect(mainwin->geometry().topLeft()+
QPoint(25,mainwin->height()*2/3),
172 QSize(frmMain->width()+15, 0)));
173 setAttribute(Qt::WA_ShowWithoutActivating,
true);
174 setProperty(
"klfTopLevelWidget",
QVariant(
true));
175 setAttribute(Qt::WA_StyledBackground,
true);
176 setStyleSheet(mainwin->
window()->styleSheet());
183 connect(
this, SIGNAL(linkActivated(
const QString&)),
184 this, SLOT(internalLinkActivated(
const QString&)));
185 connect(
this, SIGNAL(linkActivated(
const QUrl&)),
186 mainwin, SLOT(helpLinkAction(
const QUrl&)));
196 void linkActivated(
const QUrl& url);
205 klfDbg(
"adding message "<<msgKey<<
" -> "<<msgText);
207 messages << (
"<p>"+msgText+
"</p>");
213 int i = msgKeys.indexOf(msgKey);
217 messages.removeAt(i);
224 setStyleSheet(styleSheet());
228 void internalLinkActivated(
const QString& url)
235 setText(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\"" 236 " \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" 237 "<html><head><meta name=\"qrichtext\" content=\"1\" />" 238 "<style type=\"text/css\">\n" 239 "body { margin: 2px 10px; }\n" 240 "p { white-space: pre-wrap; padding: 0px; margin: 0px 0px 2px 0px; }\n" 241 "a, a:link { text-decoration: underline; color: #0000af }\n" 242 "a:hover { color: #0000ff }\n" 243 "a:active { color: #ff0000 }\n" 248 + messages.join(
"\n") +
249 "<p style=\"margin-top: 5px\">" 250 "<a href=\"klfaction:/popup?acceptAll\">"+tr(
"Accept [<b>Alt-Enter</b>]")+
"</a> | "+
251 " <a href=\"klfaction:/popup_close\">"+tr(
"Close [<b>Esc</b>]")+
"</a> | " +
252 " <a href=\"klfaction:/popup?configDontShow\">"+tr(
"Don't Show Again")+
"</a></p>"+
254 resize(width(), sizeHint().height());
282 <<
"application/x-klf-libentries" 283 <<
"application/x-klatexformula" 284 <<
"application/x-klatexformula-db" ;
287 for (k = 0; k < fmts.
size(); ++k) {
288 types <<
"image/"+fmts[k].toLower();
289 types <<
"image/x-"+fmts[k].toLower();
291 klfDbg(
"mime types: "<<types) ;
301 bool r = f.
open(QIODevice::ReadOnly);
303 klfDbg(
" ... file cannot be accessed.") ;
306 bool isimage =
false;
307 if (isKlfImage(&f, &isimage)) {
308 klfDbg(
" ... is KLF-saved image.") ;
312 klfDbg(
" ... is a non-KLF image.") ;
318 klfDbg(
" ... libscheme="<<libscheme) ;
322 klfDbg(
" ... not recognized.") ;
330 buf.open(QIODevice::ReadOnly);
332 if (isKlfImage(&buf, &isimg))
357 klfDbg(
" ... file is not readable") ;
364 bool r = f.
open(QIODevice::ReadOnly);
366 klfDbg(
" ... file cannot be opened") ;
369 bool isimage =
false;
370 if (tryOpenImageData(&f, &isimage)) {
371 klfDbg(
" ... loaded image data!") ;
375 klfDbg(
" ... is non-KLF image...") ;
383 bool result = mainWin()->openLibFile(file);
385 klfDbg(
"mainWin()->openLibFile("<<file<<
") returned "<<result) ;
396 klfDbg(
"mimetype is "<<mimetype) ;
400 buf.open(QIODevice::ReadOnly);
402 if (mimetype ==
"text/uri-list") {
403 klfDbg(
"Opening uri-list") ;
408 while ((len = buf.readLine(sbuf,
sizeof(sbuf))) > 0) {
412 if (url.
scheme() !=
"file") {
413 qWarning()<<
KLF_FUNC_NAME<<
": can't open URL "<<url.
scheme()<<
" (can only open local files)";
417 klfDbg(
"... added file "<<flist.last()) ;
419 if (flist.isEmpty()) {
420 klfDbg(
"file list is empty.") ;
423 return mainWin()->openFiles(flist);
426 bool isimage =
false;
427 if (tryOpenImageData(&buf, &isimage))
433 if (tryOpenKlfLibEntries(&buf))
447 klfDbg(
"format "<<imagereader->
format()<<
": canRead() returned FALSE!") ;
450 *img = imagereader->
read();
452 klfDbg(
"read() returned a null qimage!") ;
457 <<
"; error="<<imagereader->
error()
458 <<
"; quality="<<imagereader->
quality()
459 <<
"; supportsOption(description)="<<imagereader->
supportsOption(QImageIOHandler::Description)
460 <<
"; text('AppVersion')="<<img->
text(
"AppVersion")
462 if (!img->
text(
"AppVersion").startsWith(
"KLatexFormula ") && !img->
text(
"AppVersion").startsWith(
"KLF ")) {
463 klfDbg(
"AppVersion is not set to 'KL[atex]F[ormula] [...]' in image metadata.") ;
469 bool isKlfImage(
QIODevice *device,
bool *isImage)
475 for (k = 0; k < formatlist.
size(); ++k) {
479 if (prepareImageReader(&imagereader, &img, isImage))
484 bool tryOpenImageData(
QIODevice *device,
bool *isimage)
490 for (k = 0; k < formatlist.
size(); ++k) {
494 if (!prepareImageReader(&imagereader, &img, isimage))
504 style.
dpi = img.
text(
"InputDPI").toInt();
506 mainWin()->slotLoadStyle(style);
507 mainWin()->slotSetLatex(latex);
512 unsigned long read_color(
const QString& text)
515 QRegExp rx1(
"\\s*rgba?\\s*\\(\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)(\\s*,\\s*(\\d+))?\\s*\\)\\s*");
517 if (rx1.
cap(4).isEmpty())
518 return qRgb(rx1.
cap(1).toInt(), rx1.
cap(2).toInt(), rx1.
cap(3).toInt());
520 return qRgba(rx1.
cap(1).toInt(), rx1.
cap(2).toInt(), rx1.
cap(3).toInt(), rx1.
cap(5).toInt());
527 bool tryOpenKlfLibEntries(
QIODevice *dev)
537 QVariantMap properties;
539 stream >> properties >> entries;
540 if (entries.size() > 1) {
542 tr(
"The data you have request to open contains multiple formulas.\n" 543 "You may only open one formula into the LaTeX code editor."));
546 if (entries.size() == 0) {
548 tr(
"The data you have request to open contains no formulas."));
578 bool r = f.
open(QIODevice::ReadOnly);
583 if (f.read(4) ==
"qres")
601 if (!canOpenFile(file)) {
602 klfDbg(
"file is not openable by us: "<<file);
606 mainWin()->settingsDialog()->show();
608 mainWin()->settingsDialog()->importAddOn(file,
true);
void removeMessage(const QString &msgKey)
virtual ~KLFHelpDialogCommon()
setPointSize(int pointSize)
virtual ~KLFAboutDialog()
virtual bool openData(const QByteArray &data, const QString &mimetype)
virtual ~KLFBasicDataOpener()
virtual bool canOpenFile(const QString &file)
KLF_EXPORT int klfVersionMin()
virtual QStringList supportedMimeTypes()
KLF_EXPORT int klfVersionMaj()
setData(const QByteArray &data)
virtual void addExtraText(const QString &htmlSnipplet)
#define klfDbg(streamableItems)
#define KLF_DEBUG_BLOCK(msg)
virtual bool canOpenData(const QByteArray &data)
text(const QString &key=QString()
replace(int position, int n, const QString &after)
virtual ~KLFAddOnDataOpener()
fromUtf8(const char *str, int size=-1)
KLFHelpDialogCommon(const QString &baseFName)
KLF_EXPORT QString klfUrlLocalFilePath(const QUrl &url)
virtual QString getFullHtml()
virtual ~KLFMainWinPopup()
void addMessage(const QString &msgKey, const QString &msgText)
virtual bool openData(const QByteArray &, const QString &)
virtual QStringList supportedMimeTypes()
virtual bool canOpenFile(const QString &file)
KLFMainWinPopup(KLFMainWin *mainwin)
KLFBasicDataOpener(KLFMainWin *mainwin)
virtual ~KLFWhatsNewDialog()
KLF_EXPORT QString klfFindTranslatedDataFile(const QString &baseFileName, const QString &extension)
virtual bool openFile(const QString &file)
KLFWhatsNewDialog(QWidget *parent)
critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
supportsOption(QImageIOHandler::ImageOption option)
KLFAboutDialog(QWidget *parent)
setDevice(QIODevice *device)
virtual bool canOpenData(const QByteArray &)
KLFAddOnDataOpener(KLFMainWin *mainwin)
QStringList pHtmlExtraSnipplets
exactMatch(const QString &str)
fromEncoded(const QByteArray &input)
virtual bool openFile(const QString &file)
QStringList messageKeys()