diff --git a/src/qml/TextDelegate.qml b/src/qml/TextDelegate.qml index c8a9b70..2974a9f 100644 --- a/src/qml/TextDelegate.qml +++ b/src/qml/TextDelegate.qml @@ -1,49 +1,54 @@ /* KLook * Copyright (c) 2011-2012 ROSA * Authors: Julia Mineeva, Evgeniy Auzhin, Sergey Borovkov. * License: GPLv3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 3, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.0 +import QtQuick 2.7 import Widgets 1.0 Component { id: txtDelegate Item { id: txtItem PlainText { id: txt source: filePath //anchors.fill: parent FIXME preview: false } + TextEdit { + id: textViewer + text:txt.content + } + Connections{ target: photosListView; onCurrentIndexChanged: { if ( listItem.ListView.isCurrentItem ) { //Disable scrolling in embedded mode if (mainWindow.state === 'embedded') txt.setPreview(true) } } } } } diff --git a/src/text.cpp b/src/text.cpp index 1f7892a..4574365 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -1,93 +1,85 @@ /* KLook * Copyright (c) 2011-2012 ROSA * Authors: Julia Mineeva, Evgeniy Auzhin, Sergey Borovkov. * License: GPLv3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 3, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "text.h" #include #include -#include #include #include -MyText::MyText(QGraphicsItem* parent) - : QGraphicsProxyWidget(parent) +MyText::MyText(QObject* parent) + : QObject(parent) , m_isPreview(false) { - m_viewer = new QPlainTextEdit(); - m_viewer->setReadOnly(true); - m_viewer->viewport()->setCursor(Qt::ArrowCursor); - m_viewer->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); - - setWidget(m_viewer); } MyText::~MyText() { } QString MyText::source() const { return m_source; } void MyText::setSource(const QString& source) { if (m_source == source) { return; } m_source = source; QFile f(m_source); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } QByteArray data = f.readAll().data(); KEncodingProber prober(KEncodingProber::Universal); prober.feed(data); - QString str; if (prober.confidence() > 0.7) { - str = QTextCodec::codecForName(prober.encoding())->toUnicode(data); + m_sourceContent = QTextCodec::codecForName(prober.encoding())->toUnicode(data); } else { - str = QString::fromUtf8(data); + m_sourceContent = QString::fromUtf8(data); } - m_viewer->setPlainText(str); emit sourceChanged(); + emit contentChanged(); emit ready(); } bool MyText::isPreview() const { return m_isPreview; } void MyText::setPreview(bool preview) { m_isPreview = preview; Qt::ScrollBarPolicy policy = m_isPreview ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAsNeeded; - m_viewer->setVerticalScrollBarPolicy(policy); - m_viewer->setHorizontalScrollBarPolicy(policy); + //m_viewer->setVerticalScrollBarPolicy(policy); + //m_viewer->setHorizontalScrollBarPolicy(policy); TODO, FIXME: change those things in the delegate on the TextEdit } diff --git a/src/text.h b/src/text.h index 7e49ae5..8a06f65 100644 --- a/src/text.h +++ b/src/text.h @@ -1,58 +1,59 @@ /* KLook * Copyright (c) 2011-2012 ROSA * Authors: Julia Mineeva, Evgeniy Auzhin, Sergey Borovkov. * License: GPLv3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 3, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MYTEXT_H #define MYTEXT_H -#include +#include class QPlainTextEdit; -class MyText : public QGraphicsProxyWidget +class MyText : public QObject { Q_OBJECT Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString content MEMBER m_sourceContent NOTIFY contentChanged) Q_PROPERTY(bool preview READ isPreview WRITE setPreview) public: - MyText(QGraphicsItem* parent = 0); + MyText(QObject* parent = 0); ~MyText(); public slots: QString source() const; void setSource(const QString& source); bool isPreview() const; void setPreview(bool preview); Q_SIGNALS: void sourceChanged(); + void contentChanged(); void ready(); private: - QPlainTextEdit* m_viewer; QString m_source; + QString m_sourceContent; bool m_isPreview; - }; #endif // MYTEXT_H