view->setAlignment(Qt::AlignCenter);
view->show();
- QDeclarativeView *view2 = new QDeclarativeView();
+ /* QDeclarativeView *view2 = new QDeclarativeView();
view2->setSource(QUrl("src/mdictionary/qml/TranslationView.qml"));
view2->setResizeMode(QDeclarativeView::SizeRootObjectToView);
view2->setAlignment(Qt::AlignCenter);
view2->show();
-
+*/
mainLayout = new QVBoxLayout;
mainLayout->addWidget(view);
view->setAlignment(Qt::AlignCenter);
view->show();
+ mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(view);
+ setLayout(mainLayout);
+
+ QGraphicsObject *rootObject = view->rootObject();
+
+ connect(this, SIGNAL(setUrl(QVariant)),
+ rootObject, SLOT(setUrl(QVariant)));
#else
realParent = qobject_cast<TranslationWidget*>(parent);
#endif
}
+void TranslationView::setHtml(QString htmlString){
+ QString url = QDir::homePath() + "/.mdictionary/" + "html.html";
+ QFile file(url);
+ if(file.open(QIODevice::WriteOnly | QIODevice::Text)){
+ QByteArray array = htmlString.toUtf8();
+ file.write(array);
+ file.close();
+ emit setUrl(url);
+ }
+}
+
void TranslationView::wheelEvent(QWheelEvent *e) {
+#ifndef Q_WS_MAEMO_5
+#else
if(e->modifiers() & Qt::ControlModifier) {
if(e->delta()>0) {
zoomIn();
else {
QWebView::wheelEvent(e);
}
+#endif
}
bool TranslationView::eventFilter(QObject *, QEvent *e) {
+#ifndef Q_WS_MAEMO_5
+#else
switch (e->type()) {
case QEvent::MouseButtonPress:
if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
break;
}
return false;
+#endif
}
void TranslationView::contextMenuEvent(QContextMenuEvent *e) {
+#ifndef Q_WS_MAEMO_5
+#else
QMenu *menu = new QMenu;
if(selectedText().isEmpty())
searchSelectedAction->setEnabled(false);
delete menu;
e->ignore();
+#endif
}
void TranslationView::zoomIn() {
+#ifndef Q_WS_MAEMO_5
+#else
if(zoomFactor() >= 3)
return;
setZoomFactor(zoomFactor()*1.05);
realParent->updateZoom(zoomFactor());
-
+#endif
}
void TranslationView::zoomOut() {
+#ifndef Q_WS_MAEMO_5
+#else
if(zoomFactor() <= 0.5)
return;
setZoomFactor(zoomFactor()*0.95);
realParent->updateZoom(zoomFactor());
+#endif
}
void TranslationView::copy() {
+#ifndef Q_WS_MAEMO_5
+#else
pageAction(QWebPage::Copy)->trigger();
+#endif
}
void TranslationView::selection() {
+#ifndef Q_WS_MAEMO_5
+#else
if(selectedText().size())
Q_EMIT copyAvailable(true);
else
Q_EMIT copyAvailable(false);
+#endif
}
void TranslationView::selectAll() {
+#ifndef Q_WS_MAEMO_5
+#else
pageAction(QWebPage::SelectAll)->trigger();
+#endif
}
#include <QEvent>
#include <QDeclarativeView>
#include <QVBoxLayout>
+#include <QString>
+#include <QByteArray>
class TranslationWidget;
Q_OBJECT
public:
explicit TranslationView(QWidget *parent = 0);
+ void setHtml(QString htmlString);
public Q_SLOTS:
void zoomIn();
Q_SIGNALS:
void search();
void copyAvailable(bool);
+ void setHtmlSignal(QVariant htmlString);
+ void setUrl(QVariant url);
protected:
void contextMenuEvent(QContextMenuEvent *);
setWindowTitle("mDictionary");
- connect(webkit, SIGNAL(search()),
- this, SLOT(searchSelected()));
+// connect(webkit, SIGNAL(search()),
+// this, SLOT(searchSelected()));
QFile file(":/xsl/xsl.xsl");
if(!file.open(QFile::ReadOnly))
QString trans= createTranslation(translations);
QString head = "<html><head>";
- head += "<link rel=\"stylesheet\" type=\"text/css\" "
+ head += "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"> "
+ "<link rel=\"stylesheet\" type=\"text/css\" "
"href=\"/usr/share/mdictionary/css/" "style.css"
"\" /></head><body ondragstart=\"return false\">";
trans = head + trans + "</body></html>";
trans.replace("$STAR$", "/usr/share/mdictionary/staron.png");
- webkit->setHtml(trans, QUrl().fromLocalFile("/"));
+ webkit->setHtml(trans);
+// webkit->setHtml(trans, QUrl().fromLocalFile("/"));
}
qreal fac = set->value("zoom").toFloat();
if(!fac)
fac++;
- webkit->setZoomFactor(fac);
+// webkit->setZoomFactor(fac);
delete set;
QWidget*w = new QWidget(this);
}
void TranslationWidget::searchSelected() {
- if(webkit->selectedText().isEmpty()) {
+/* if(webkit->selectedText().isEmpty()) {
Q_EMIT notify(Notify::Warning, tr("No text is selected"));
}
else {
#endif
Q_EMIT search(webkit->selectedText().toLower());
}
+ */
}
void TranslationWidget::copySelected() {
- if(webkit->selectedText().isEmpty()) {
+ /* if(webkit->selectedText().isEmpty()) {
Q_EMIT notify(Notify::Warning, tr("No text is selected"));
}
else {
Q_EMIT notify(Notify::Info, tr("Copyied selected text"));
}
+ */
}
#ifdef Q_WS_MAEMO_5
void TranslationWidget::keyPressEvent(QKeyEvent* event) {
switch (event->key()) {
case Qt::Key_F7:
- webkit->zoomIn();
+ // webkit->zoomIn();
event->accept();
break;
case Qt::Key_F8:
- webkit->zoomOut();
+// webkit->zoomOut();
event->accept();
break;
}
qml/DictTypeSelectDialog.qml \
qml/DictManagerWidget.qml \
qml/WordListWidget.qml \
- qml/TranslationView.qml
+ qml/TranslationView.qml \
+ qml/FlickableWebView.qml \
+ qml/ScrollBar.qml
target.path = $$BIN_DIR
INSTALLS += target
qmls.files += ./qml/DictManagerWidget.qml
qmls.files += ./qml/WordListWidget.qml
qmls.files += ./qml/TranslationView.qml
+ qmls.files += ./qml/FlickableWebView.qml
+ qmls.files += ./qml/ScrollBar.qml
}
INSTALLS += desktop icon64 shared service css css_images qmls
import QtWebKit 1.0
Rectangle {
- id: rectangle1
+ id: webBrowser
width: 500
height: 500
+ SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
+ color: myPalette.window
+ function setUrl(string){
+ webView.url = "file:///home/jakub/Pulpit/test.html";
+ webView.url = "file:///home/jakub/.mdictionary/html.html";
+ }
+
+ FlickableWebView {
+ id: webView
+ width:parent.width
+ height:parent.height
+ anchors { top: headerSpace.bottom; left: parent.left; right: parent.right; bottom: parent.bottom }
+ }
- WebView {
- id: web_view1
- anchors.fill: parent
- url: "http://kokos.pl/"
+ Item { id: headerSpace; width: parent.width; height: 1}
+
+ ScrollBar {
+ scrollArea: webView; width: 8
+ anchors { right: parent.right; top: parent.bottom; bottom: parent.bottom }
+ }
- onDoubleClick: {
- console.log(clickX,clickY);
- heuristicZoom(clickX,clickY,2)
- }
- /* onZoomTo: {
- console.log(zoom);
- scale=zoom;x=width/2-centerX;
- y=height/2-centerY
- }
- */
+ ScrollBar {
+ scrollArea: webView; height: 8; orientation: Qt.Horizontal
+ anchors { right: parent.right; rightMargin: 8; left: parent.left; bottom: parent.bottom }
}
Button {
id: button1
- textInButton: "test"
- width: 200;
- height: 30;
- x: 41
- y: 28
- onClicked: web_view1.scale=web_view1.scale*1.05;
+ textInButton: "+"
+ width: 20;
+ height: 20;
+ anchors.right: parent.right
+ anchors.bottom: button2.top
+ onClicked: webView.doZoom(1.05);
}
Button {
id: button2
- textInButton: "test2"
- width: 200;
- height: 30;
- x: 41
- y: 68
- onClicked: web_view1.scale=web_view1.scale*.95;
+ textInButton: "-"
+ width: 20;
+ height: 20;
+ anchors.right: parent.right
+ anchors.bottom: parent.bottom
+ onClicked: webView.doZoom(.95);
}
}