source: subversion/applications/editors/merkaartor/InfoDock.cpp @ 13989

Last change on this file since 13989 was 13422, checked in by Łukasz Jernaś, 11 years ago

FIX : Implement dynamic UI translation (fixes #1432)

File size: 2.3 KB
Line 
1//
2// C++ Implementation: InfoDock
3//
4// Description:
5//
6//
7// Author: cbro <cbro@semperpax.com>, (C) 2008
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include "InfoDock.h"
13#include "MainWindow.h"
14#include "Preferences/MerkaartorPreferences.h"
15#include "Map/DownloadOSM.h"
16
17#include <QMessageBox>
18
19InfoDock::InfoDock(MainWindow* aParent)
20        : MDockAncestor(aParent), Main(aParent), theText(new QTextBrowser(this))
21{
22        setMinimumSize(220,100);
23        setWindowTitle(tr("Info"));
24        setObjectName("infoDock");
25
26        theText->setReadOnly(true);
27        theText->setOpenLinks(false);
28        setWidget(theText);
29
30        connect(theText, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(on_anchorClicked(const QUrl &)));
31        retranslateUi();
32}
33
34
35InfoDock::~InfoDock()
36{
37}
38
39void InfoDock::setHtml(QString html)
40{
41        currentHtml = html;
42        theText->setHtml(html);
43}
44
45void InfoDock::setHoverHtml(QString html)
46{
47        theText->setHtml(html);
48}
49
50void InfoDock::unsetHoverHtml()
51{
52        theText->setHtml(currentHtml);
53}
54
55QString InfoDock::getHtml()
56{
57        return theText->toHtml();
58}
59
60void InfoDock::on_anchorClicked(const QUrl & link)
61{
62        QHttp http;
63        QString data;
64
65        QString osmWebsite = MerkaartorPreferences::instance()->getOsmWebsite();
66        QString osmUser = MerkaartorPreferences::instance()->getOsmUser();
67        QString osmPwd = MerkaartorPreferences::instance()->getOsmPassword();
68
69        bool useProxy = MerkaartorPreferences::instance()->getProxyUse();
70        QString proxyHost = MerkaartorPreferences::instance()->getProxyHost();
71        int proxyPort = MerkaartorPreferences::instance()->getProxyPort();
72
73        Downloader theDownloader(osmWebsite, osmUser, osmPwd, useProxy, proxyHost, proxyPort);
74
75        if (theDownloader.request("GET", link.path(), data)) {
76                QTextBrowser* b = new QTextBrowser;
77                QString s = QString::fromUtf8(theDownloader.content().constData());
78                b->setPlainText(s);
79                b->setAttribute(Qt::WA_DeleteOnClose,true);
80                b->resize(640, 480);
81                b->show();
82                b->raise();
83        } else {
84                QMessageBox::warning(Main,QApplication::translate("Downloader","Download failed"),QApplication::translate("Downloader","Unexpected http status code (%1)").arg(theDownloader.resultCode()));
85        }
86}
87
88void InfoDock::changeEvent(QEvent *event)
89{
90        if (event->type() == QEvent::LanguageChange)
91                retranslateUi();
92        MDockAncestor::changeEvent(event);
93}
94
95void InfoDock::retranslateUi()
96{
97        setWindowTitle(tr("Info"));
98}
99
Note: See TracBrowser for help on using the repository browser.