diff options
author | Kandrashin Denis <mail@lintest.ru> | 2012-11-07 10:53:54 +0400 |
---|---|---|
committer | Kandrashin Denis <mail@lintest.ru> | 2012-11-07 13:00:33 +0400 |
commit | a045bb4dddb2efda55e235e7a8069fa34853c729 (patch) | |
tree | d83f311cb418ef6e91c821baaa4ae97d179131f9 | |
parent | 577780bc37c70fdd78257cdd49313451ddd9e564 (diff) |
Rename file: fb2temp.cpp => fb2imgs.cpp
-rw-r--r-- | fb2edit.pro | 4 | ||||
-rw-r--r-- | source/fb2dlgs.cpp | 141 | ||||
-rw-r--r-- | source/fb2dlgs.hpp | 47 | ||||
-rw-r--r-- | source/fb2imgs.cpp (renamed from source/fb2temp.cpp) | 228 | ||||
-rw-r--r-- | source/fb2imgs.hpp (renamed from source/fb2temp.hpp) | 78 | ||||
-rw-r--r-- | source/fb2page.cpp | 2 | ||||
-rw-r--r-- | source/fb2read.cpp | 2 | ||||
-rw-r--r-- | source/fb2save.cpp | 17 | ||||
-rw-r--r-- | source/fb2save.hpp | 5 | ||||
-rw-r--r-- | source/fb2text.cpp | 30 | ||||
-rw-r--r-- | source/fb2text.hpp | 2 | ||||
-rw-r--r-- | source/res/fb2edit.qrc | 1 |
12 files changed, 300 insertions, 257 deletions
diff --git a/fb2edit.pro b/fb2edit.pro index ddf7182..e83f161 100644 --- a/fb2edit.pro +++ b/fb2edit.pro @@ -7,10 +7,10 @@ HEADERS = \ source/fb2dlgs.hpp \ source/fb2dock.hpp \ source/fb2head.hpp \ + source/fb2imgs.hpp \ source/fb2main.hpp \ source/fb2page.hpp \ source/fb2read.hpp \ - source/fb2temp.hpp \ source/fb2tree.hpp \ source/fb2save.hpp \ source/fb2text.hpp \ @@ -24,11 +24,11 @@ SOURCES = \ source/fb2dock.cpp \ source/fb2head.cpp \ source/fb2html.cpp \ + source/fb2imgs.cpp \ source/fb2main.cpp \ source/fb2page.cpp \ source/fb2read.cpp \ source/fb2save.cpp \ - source/fb2temp.cpp \ source/fb2tree.cpp \ source/fb2xml.cpp \ source/fb2xml2.cpp \ diff --git a/source/fb2dlgs.cpp b/source/fb2dlgs.cpp index 0c96f14..9dd9e26 100644 --- a/source/fb2dlgs.cpp +++ b/source/fb2dlgs.cpp @@ -166,144 +166,3 @@ FbSetupDlg::FbSetupDlg(QWidget *parent) { ui->setupUi(this); } - -//--------------------------------------------------------------------------- -// FbComboCtrl -//--------------------------------------------------------------------------- - -FbComboCtrl::FbComboCtrl(QWidget *parent) - : QLineEdit(parent) -{ - button = new QToolButton(this); - button->setCursor(Qt::ArrowCursor); - button->setFocusPolicy(Qt::NoFocus); - connect(button, SIGNAL(clicked()), SIGNAL(popup())); - QHBoxLayout *layout = new QHBoxLayout(this); - layout->addWidget(button, 0, Qt::AlignRight); - layout->setSpacing(0); - layout->setMargin(0); -} - -void FbComboCtrl::resizeEvent(QResizeEvent* event) -{ - QLineEdit::resizeEvent(event); - QMargins margins(0, 0, button->width(), 0); - setTextMargins(margins); -} - -void FbComboCtrl::setIcon(const QIcon &icon) -{ - button->setIcon(icon); -} - -//--------------------------------------------------------------------------- -// FbImageDlg::FbTab -//--------------------------------------------------------------------------- - -FbImageDlg::FbTab::FbTab(QWidget* parent, QAbstractItemModel *model) - : QWidget(parent) - , combo(0) - , edit(0) -{ - QGridLayout * layout = new QGridLayout(this); - - label = new QLabel(this); - label->setText(tr("File name:")); - layout->addWidget(label, 0, 0, 1, 1); - - QWidget *control; - if (model) { - control = combo = new QComboBox(this); - combo->setModel(model); - } else { - control = edit = new FbComboCtrl(this); - } - - QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - control->setSizePolicy(sizePolicy); - layout->addWidget(control, 0, 1, 1, 1); - - QFrame *frame = new FbTextFrame(this); - frame->setMinimumSize(QSize(300, 200)); - layout->addWidget(frame, 1, 0, 1, 2); - - preview = new QWebView(this); - frame->layout()->addWidget(preview); -} - -//--------------------------------------------------------------------------- -// FbImageDlg -//--------------------------------------------------------------------------- - -FbImageDlg::FbImageDlg(FbTextEdit *text) - : QDialog(text) - , tabFile(0) - , tabPict(0) -{ - setWindowTitle(tr("Insert picture")); - - QLayout *layout = new QVBoxLayout(this); - - notebook = new QTabWidget(this); - layout->addWidget(notebook); - - QDialogButtonBox *buttons = new QDialogButtonBox(this); - buttons->setOrientation(Qt::Horizontal); - buttons->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); - layout->addWidget(buttons); - - connect(buttons, SIGNAL(accepted()), SLOT(accept())); - connect(buttons, SIGNAL(rejected()), SLOT(reject())); - connect(notebook, SIGNAL(currentChanged(int)), SLOT(notebookChanged(int))); - - QUrl url = text->url(); - - tabFile = new FbTab(notebook); - tabFile->edit->setIcon(FbIcon("document-open")); - tabFile->preview->setHtml(QString(), url); - connect(tabFile->edit, SIGNAL(popup()), SLOT(selectFile())); - notebook->addTab(tabFile, tr("Select file")); - - if (text->store()->count()) { - FbListModel *model = new FbListModel(text, this); - tabPict = new FbTab(notebook, model); - tabPict->preview->setHtml(QString(), url); - tabPict->combo->setCurrentIndex(0); - tabPict->preview->page()->setNetworkAccessManager(text->page()->networkAccessManager()); - notebook->addTab(tabPict, tr("From collection")); - connect(tabPict->combo, SIGNAL(activated(QString)), SLOT(pictureActivated(QString))); - } - - tabFile->edit->setFocus(); - resize(minimumSizeHint()); -} - -void FbImageDlg::notebookChanged(int index) -{ - if (index) { - disconnect(notebook, SIGNAL(currentChanged(int)), this, SLOT(notebookChanged(int))); - if (tabPict) pictureActivated(tabPict->combo->itemText(0)); - } -} - -void FbImageDlg::selectFile() -{ - QString filters; - filters += tr("Common Graphics (*.png *.jpg *.jpeg *.gif)") += ";;"; - filters += tr("Portable Network Graphics (PNG) (*.png)") += ";;"; - filters += tr("JPEG (*.jpg *.jpeg)") += ";;"; - filters += tr("Graphics Interchange Format (*.gif)") += ";;"; - filters += tr("All Files (*)"); - QWidget *p = qobject_cast<QWidget*>(parent()); - QString path = QFileDialog::getOpenFileName(p, tr("Insert image..."), QString(), filters); - if (!path.isEmpty()) tabFile->edit->setText(path); -} - -void FbImageDlg::pictureActivated(const QString & text) -{ - QUrl url = tabPict->preview->url(); - url.setFragment(text); - QString html = QString("<img src=%1 valign=center align=center width=100%>").arg(url.toString()); - tabPict->preview->setHtml(html, tabPict->preview->url()); -} - diff --git a/source/fb2dlgs.hpp b/source/fb2dlgs.hpp index 7707c62..527016e 100644 --- a/source/fb2dlgs.hpp +++ b/source/fb2dlgs.hpp @@ -80,51 +80,4 @@ private: Ui::FbSetup * ui; }; -#include <QVBoxLayout> -#include <QToolButton> -#include <QLineEdit> - -class FbComboCtrl : public QLineEdit -{ - Q_OBJECT -public: - explicit FbComboCtrl(QWidget *parent = 0); - void setIcon(const QIcon &icon); -signals: - void popup(); -protected: - void resizeEvent(QResizeEvent* event); -private: - QToolButton *button; -}; - -class FbImageDlg : public QDialog -{ - Q_OBJECT - -private: - class FbTab: public QWidget - { - public: - explicit FbTab(QWidget* parent, QAbstractItemModel *model = 0); - QLabel *label; - QComboBox *combo; - FbComboCtrl *edit; - QWebView *preview; - }; - -public: - explicit FbImageDlg(FbTextEdit *text); - -private slots: - void pictureActivated(const QString & text); - void notebookChanged(int index); - void selectFile(); - -private: - QTabWidget *notebook; - FbTab *tabFile; - FbTab *tabPict; -}; - #endif // FB2DLGS_H diff --git a/source/fb2temp.cpp b/source/fb2imgs.cpp index 9ab1135..69372b9 100644 --- a/source/fb2temp.cpp +++ b/source/fb2imgs.cpp @@ -1,17 +1,28 @@ -#include "fb2temp.hpp" +#include "fb2imgs.hpp" #include <QAbstractListModel> #include <QBuffer> #include <QCryptographicHash> +#include <QDialogButtonBox> +#include <QFileDialog> #include <QFileInfo> #include <QImageReader> +#include <QLabel> +#include <QLineEdit> #include <QUrl> -#include <QWebFrame> #include <QVBoxLayout> +#include <QWebFrame> +#include <QTabWidget> #include <QtDebug> #include "fb2page.hpp" #include "fb2text.hpp" +#include "fb2utils.h" + +static QString imgHtml(const QUrl &url) +{ + return QString("<img src=\"%1\" valign=center align=center width=100%>").arg(url.toString()); +} //--------------------------------------------------------------------------- // FbBinary @@ -254,29 +265,201 @@ QByteArray FbNetworkAccessManager::data(int index) const } //--------------------------------------------------------------------------- -// FbListModel +// FbComboCtrl //--------------------------------------------------------------------------- -FbListModel::FbListModel(FbTextEdit *text, QObject *parent) +FbComboCtrl::FbComboCtrl(QWidget *parent) + : QLineEdit(parent) +{ + button = new QToolButton(this); + button->setCursor(Qt::ArrowCursor); + button->setFocusPolicy(Qt::NoFocus); + connect(button, SIGNAL(clicked()), SIGNAL(popup())); + QHBoxLayout *layout = new QHBoxLayout(this); + layout->addWidget(button, 0, Qt::AlignRight); + layout->setSpacing(0); + layout->setMargin(0); +} + +void FbComboCtrl::resizeEvent(QResizeEvent* event) +{ + QLineEdit::resizeEvent(event); + QMargins margins(0, 0, button->width(), 0); + setTextMargins(margins); +} + +void FbComboCtrl::setIcon(const QIcon &icon) +{ + button->setIcon(icon); +} + +//--------------------------------------------------------------------------- +// FbImageDlg::FbTab +//--------------------------------------------------------------------------- + +FbImageDlg::FbTab::FbTab(QWidget* parent, QAbstractItemModel *model) + : QWidget(parent) + , combo(0) + , edit(0) +{ + QGridLayout * layout = new QGridLayout(this); + + label = new QLabel(this); + label->setText(tr("File name:")); + layout->addWidget(label, 0, 0, 1, 1); + + QWidget *control; + if (model) { + control = combo = new QComboBox(this); + combo->setModel(model); + } else { + control = edit = new FbComboCtrl(this); + } + + QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + control->setSizePolicy(sizePolicy); + layout->addWidget(control, 0, 1, 1, 1); + + QFrame *frame = new FbTextFrame(this); + frame->setMinimumSize(QSize(300, 200)); + layout->addWidget(frame, 1, 0, 1, 2); + + preview = new QWebView(this); + frame->layout()->addWidget(preview); +} + +//--------------------------------------------------------------------------- +// FbImageDlg +//--------------------------------------------------------------------------- + +FbImageDlg::FbImageDlg(FbTextEdit *text) + : QDialog(text) + , owner(text) + , tabFile(0) + , tabPict(0) +{ + setWindowTitle(tr("Insert picture")); + + QLayout *layout = new QVBoxLayout(this); + + notebook = new QTabWidget(this); + layout->addWidget(notebook); + + QDialogButtonBox *buttons = new QDialogButtonBox(this); + buttons->setOrientation(Qt::Horizontal); + buttons->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + layout->addWidget(buttons); + + connect(buttons, SIGNAL(accepted()), SLOT(accept())); + connect(buttons, SIGNAL(rejected()), SLOT(reject())); + connect(notebook, SIGNAL(currentChanged(int)), SLOT(notebookChanged(int))); + + tabFile = new FbTab(notebook); + tabFile->edit->setIcon(FbIcon("document-open")); + tabFile->preview->setHtml(QString()); + connect(tabFile->edit, SIGNAL(textChanged(QString)), SLOT(filenameChanged(QString))); + connect(tabFile->edit, SIGNAL(popup()), SLOT(selectFile())); + notebook->addTab(tabFile, tr("Select file")); + + if (text->store()->count()) { + FbImgsModel *model = new FbImgsModel(text, this); + tabPict = new FbTab(notebook, model); + tabPict->combo->setCurrentIndex(0); + tabPict->preview->setHtml(QString(), text->url()); + tabPict->preview->page()->setNetworkAccessManager(text->page()->networkAccessManager()); + notebook->addTab(tabPict, tr("From collection")); + connect(tabPict->combo, SIGNAL(activated(QString)), SLOT(pictureActivated(QString))); + } + + tabFile->edit->setFocus(); + resize(minimumSizeHint()); +} + +void FbImageDlg::notebookChanged(int index) +{ + if (index) { + disconnect(notebook, SIGNAL(currentChanged(int)), this, SLOT(notebookChanged(int))); + if (tabPict) pictureActivated(tabPict->combo->itemText(0)); + } +} + +void FbImageDlg::selectFile() +{ + QString filters; + filters += tr("Common Graphics (*.png *.jpg *.jpeg *.gif)") += ";;"; + filters += tr("Portable Network Graphics (PNG) (*.png)") += ";;"; + filters += tr("JPEG (*.jpg *.jpeg)") += ";;"; + filters += tr("Graphics Interchange Format (*.gif)") += ";;"; + filters += tr("All Files (*)"); + QWidget *p = qobject_cast<QWidget*>(parent()); + QString path = QFileDialog::getOpenFileName(p, tr("Insert image..."), QString(), filters); + if (path.isEmpty()) return; + tabFile->edit->setText(path); +} + +void FbImageDlg::filenameChanged(const QString & text) +{ + if (QFileInfo(text).exists()) { + QUrl url = QUrl::fromLocalFile(text); + preview(tabFile->preview, url); + } else { + tabFile->preview->setHtml(QString()); + } +} + +void FbImageDlg::pictureActivated(const QString & text) +{ + QUrl url = tabPict->preview->url(); + url.setFragment(text); + preview(tabPict->preview, url); +} + +void FbImageDlg::preview(QWebView *preview, const QUrl &url) +{ + preview->setHtml(imgHtml(url), preview->url()); +} + +QString FbImageDlg::result() const +{ + if (tabPict && notebook->currentWidget() == tabPict) { + return tabPict->combo->currentText(); + } else if (notebook->currentWidget() == tabFile) { + QString path = tabFile->edit->text(); + QFile file(path); + if (file.open(QIODevice::ReadOnly)) { + QNetworkAccessManager *m = owner->page()->networkAccessManager(); + FbNetworkAccessManager *manager = qobject_cast<FbNetworkAccessManager*>(m); + QByteArray data = file.readAll(); + return manager->add(path, data); + } + } + return QString(); +} + +//--------------------------------------------------------------------------- +// FbImgsModel +//--------------------------------------------------------------------------- + +FbImgsModel::FbImgsModel(FbTextEdit *text, QObject *parent) : QAbstractListModel(parent) , m_text(text) { } -int FbListModel::columnCount(const QModelIndex &parent) const +int FbImgsModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 4; } -int FbListModel::rowCount(const QModelIndex &parent) const +int FbImgsModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); FbNetworkAccessManager * f = files(); return f ? f->count() : 0; } -QVariant FbListModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant FbImgsModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { switch (section) { @@ -288,7 +471,7 @@ QVariant FbListModel::headerData(int section, Qt::Orientation orientation, int r return QVariant(); } -FbNetworkAccessManager * FbListModel::files() const +FbNetworkAccessManager * FbImgsModel::files() const { if (FbTextPage *page = qobject_cast<FbTextPage*>(m_text->page())) { return qobject_cast<FbNetworkAccessManager*>(page->networkAccessManager()); @@ -297,7 +480,7 @@ FbNetworkAccessManager * FbListModel::files() const } } -QVariant FbListModel::data(const QModelIndex &index, int role) const +QVariant FbImgsModel::data(const QModelIndex &index, int role) const { if (index.isValid()) { switch (role) { @@ -317,35 +500,35 @@ QVariant FbListModel::data(const QModelIndex &index, int role) const } //--------------------------------------------------------------------------- -// FbListView +// FbImgsView //--------------------------------------------------------------------------- #include <QSplitter> #include <QScrollArea> -FbListView::FbListView(QWidget *parent) +FbImgsView::FbImgsView(QWidget *parent) : QTreeView(parent) { setAllColumnsShowFocus(true); } -void FbListView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) +void FbImgsView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { QTreeView::currentChanged(current, previous); QModelIndex index = model()->index(current.row(), 0); emit showImage(model()->data(index).toString()); } -FbListModel * FbListView::model() const +FbImgsModel * FbImgsView::model() const { - return qobject_cast<FbListModel*>(QTreeView::model()); + return qobject_cast<FbImgsModel*>(QTreeView::model()); } //--------------------------------------------------------------------------- -// FbListWidget +// FbImgsWidget //--------------------------------------------------------------------------- -FbListWidget::FbListWidget(FbTextEdit *text, QWidget* parent) +FbImgsWidget::FbImgsWidget(FbTextEdit *text, QWidget* parent) : QWidget(parent) , m_text(text) { @@ -355,7 +538,7 @@ FbListWidget::FbListWidget(FbTextEdit *text, QWidget* parent) QSplitter *splitter = new QSplitter(Qt::Vertical, this); - m_list = new FbListView(splitter); + m_list = new FbImgsView(splitter); splitter->addWidget(m_list); FbTextFrame *frame = new FbTextFrame(splitter); @@ -374,11 +557,10 @@ FbListWidget::FbListWidget(FbTextEdit *text, QWidget* parent) loadFinished(); } -void FbListWidget::loadFinished() +void FbImgsWidget::loadFinished() { m_view->load(QUrl()); - - m_list->setModel(new FbListModel(m_text, this)); + m_list->setModel(new FbImgsModel(m_text, this)); m_list->reset(); m_list->resizeColumnToContents(1); m_list->resizeColumnToContents(2); @@ -386,10 +568,10 @@ void FbListWidget::loadFinished() m_list->setColumnHidden(0, true); } -void FbListWidget::showImage(const QString &name) +void FbImgsWidget::showImage(const QString &name) { QUrl url = m_text->url(); url.setFragment(name); - QString html = QString("<img src=%1 valign=center align=center width=100%>").arg(url.toString()); - m_view->setHtml(html); + m_view->setHtml(imgHtml(url)); } + diff --git a/source/fb2temp.hpp b/source/fb2imgs.hpp index 636ed09..56849dd 100644 --- a/source/fb2temp.hpp +++ b/source/fb2imgs.hpp @@ -1,14 +1,19 @@ -#ifndef FB2TEMP_H -#define FB2TEMP_H +#ifndef FB2IMGS_H +#define FB2IMGS_H #include <QByteArray> +#include <QDialog> +#include <QComboBox> #include <QLabel> +#include <QLineEdit> #include <QList> #include <QNetworkAccessManager> #include <QNetworkReply> #include <QString> #include <QTemporaryFile> +#include <QToolButton> #include <QTreeView> +#include <QVBoxLayout> #include <QWebView> class FbTextEdit; @@ -115,12 +120,62 @@ private: qint64 offset; }; -class FbListModel : public QAbstractListModel +class FbComboCtrl : public QLineEdit { Q_OBJECT +public: + explicit FbComboCtrl(QWidget *parent = 0); + void setIcon(const QIcon &icon); +signals: + void popup(); +protected: + void resizeEvent(QResizeEvent* event); +private: + QToolButton *button; +}; + +class FbImageDlg : public QDialog +{ + Q_OBJECT + +private: + class FbTab: public QWidget + { + public: + explicit FbTab(QWidget* parent, QAbstractItemModel *model = 0); + QLabel *label; + QComboBox *combo; + FbComboCtrl *edit; + QWebView *preview; + }; public: - explicit FbListModel(FbTextEdit *text, QObject *parent = 0); + explicit FbImageDlg(FbTextEdit *text); + QString result() const; + +private slots: + void pictureActivated(const QString & text); + void filenameChanged(const QString & text); + void notebookChanged(int index); + void selectFile(); + +private: + void preview(QWebView *preview, const QUrl &url); + void clear(QWebView *preview); + +private: + FbTextEdit *owner; + QTabWidget *notebook; + FbTab *tabFile; + FbTab *tabPict; +}; + +class FbImgsModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit FbImgsModel(FbTextEdit *text, QObject *parent = 0); public: int rowCount(const QModelIndex &parent = QModelIndex()) const; @@ -135,13 +190,13 @@ private: FbTextEdit *m_text; }; -class FbListView : public QTreeView +class FbImgsView : public QTreeView { Q_OBJECT public: - explicit FbListView(QWidget *parent = 0); - FbListModel *model() const; + explicit FbImgsView(QWidget *parent = 0); + FbImgsModel *model() const; protected: void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); @@ -150,13 +205,12 @@ signals: void showImage(const QString &name); }; -class FbListWidget : public QWidget +class FbImgsWidget : public QWidget { Q_OBJECT public: - explicit FbListWidget(FbTextEdit *text, QWidget* parent = 0); - + explicit FbImgsWidget(FbTextEdit *text, QWidget* parent = 0); QSize sizeHint() const { return QSize(200,200); } public slots: @@ -167,8 +221,8 @@ private slots: private: FbTextEdit *m_text; - FbListView *m_list; + FbImgsView *m_list; QWebView *m_view; }; -#endif // FB2TEMP_H +#endif // FB2IMGS_H diff --git a/source/fb2page.cpp b/source/fb2page.cpp index 2af845b..697d30f 100644 --- a/source/fb2page.cpp +++ b/source/fb2page.cpp @@ -6,7 +6,7 @@ #include "fb2read.hpp" #include "fb2save.hpp" -#include "fb2temp.hpp" +#include "fb2imgs.hpp" #include "fb2utils.h" #include "fb2html.h" #include "fb2xml2.h" diff --git a/source/fb2read.cpp b/source/fb2read.cpp index cb9c057..54c6536 100644 --- a/source/fb2read.cpp +++ b/source/fb2read.cpp @@ -2,7 +2,7 @@ #include <QtDebug> -#include "fb2temp.hpp" +#include "fb2imgs.hpp" #include "fb2xml2.h" //--------------------------------------------------------------------------- diff --git a/source/fb2save.cpp b/source/fb2save.cpp index 8089c45..7dc8129 100644 --- a/source/fb2save.cpp +++ b/source/fb2save.cpp @@ -197,6 +197,14 @@ QByteArray FbSaveWriter::downloadFile(const QUrl &url) return reply->readAll(); } +QString FbSaveWriter::append(const QString &name) +{ + if (m_names.indexOf(name) < 0) { + m_names.append(name); + } + return name; +} + QString FbSaveWriter::filename(const QString &path) { FbStore *store = m_view.store(); @@ -205,17 +213,16 @@ QString FbSaveWriter::filename(const QString &path) if (path.left(1) == "#") { QString name = path.mid(1); if (store->exists(name)) { - m_names.append(name); - return name; + return append(name); + } else { + return QString(); } - return QString(); } else { QUrl url = path; QByteArray data = downloadFile(url); if (data.size() == 0) return QString(); QString name = store->add(url.path(), data); - m_names.append(name); - return name; + return append(name); } } diff --git a/source/fb2save.hpp b/source/fb2save.hpp index f05d431..c1e0bd6 100644 --- a/source/fb2save.hpp +++ b/source/fb2save.hpp @@ -2,7 +2,7 @@ #define FB2SAVE_H #include "fb2xml.h" -#include "fb2temp.hpp" +#include "fb2imgs.hpp" #include <QByteArray> #include <QFileDialog> @@ -14,7 +14,7 @@ class QComboBox; class QLabel; QT_END_NAMESPACE -#include "fb2temp.hpp" +#include "fb2imgs.hpp" class FbTextEdit; @@ -80,6 +80,7 @@ public: private: QByteArray downloadFile(const QUrl &url); void writeContentType(const QString &name, QByteArray &data); + QString append(const QString &name); private: FbTextEdit &m_view; QStringList m_names; diff --git a/source/fb2text.cpp b/source/fb2text.cpp index a12df5e..33c3c9a 100644 --- a/source/fb2text.cpp +++ b/source/fb2text.cpp @@ -356,7 +356,7 @@ void FbTextEdit::viewPictures(bool show) if (show) { if (dockImgs) { dockImgs->show(); return; } dockImgs = new FbDockWidget(tr("Pictures"), this); - dockImgs->setWidget(new FbListWidget(this, m_owner)); + dockImgs->setWidget(new FbImgsWidget(this, m_owner)); connect(dockImgs, SIGNAL(visibilityChanged(bool)), act(Fb::ViewPictures), SLOT(setChecked(bool))); connect(dockImgs, SIGNAL(destroyed()), SLOT(imgsDestroyed())); m_owner->addDockWidget(Qt::RightDockWidgetArea, dockImgs); @@ -582,25 +582,13 @@ void FbTextEdit::find() void FbTextEdit::insertImage() { - FbImageDlg(this).exec(); - return; - - QString filters; - filters += tr("Common Graphics (*.png *.jpg *.jpeg *.gif)") += ";;"; - filters += tr("Portable Network Graphics (PNG) (*.png)") += ";;"; - filters += tr("JPEG (*.jpg *.jpeg)") += ";;"; - filters += tr("Graphics Interchange Format (*.gif)") += ";;"; - filters += tr("All Files (*)"); - - QString path = QFileDialog::getOpenFileName(this, tr("Insert image..."), QString(), filters); - if (path.isEmpty()) return; - - QFile file(path); - if (!file.open(QIODevice::ReadOnly)) return; - - QByteArray data = file.readAll(); - QString name = store()->add(path, data); - execCommand("insertImage", name.prepend("#")); + FbImageDlg dlg(this); + if (dlg.exec()) { + QString name = dlg.result(); + if (name.isEmpty()) return; + QUrl url; url.setFragment(name); + execCommand("insertImage", url.toString()); + } } void FbTextEdit::insertNote() @@ -618,7 +606,7 @@ void FbTextEdit::insertLink() void FbTextEdit::execCommand(const QString &cmd, const QString &arg) { - QString javascript = QString("document.exelayoutcCommand(\"%1\",false,\"%2\")").arg(cmd).arg(arg); + QString javascript = QString("document.execCommand(\"%1\",false,\"%2\")").arg(cmd).arg(arg); page()->mainFrame()->evaluateJavaScript(javascript); } diff --git a/source/fb2text.hpp b/source/fb2text.hpp index 7e57c6e..230b925 100644 --- a/source/fb2text.hpp +++ b/source/fb2text.hpp @@ -10,7 +10,7 @@ #include <QWebView> #include "fb2mode.h" -#include "fb2temp.hpp" +#include "fb2imgs.hpp" QT_BEGIN_NAMESPACE class QMainWindow; diff --git a/source/res/fb2edit.qrc b/source/res/fb2edit.qrc index aba9e9d..68e5f9b 100644 --- a/source/res/fb2edit.qrc +++ b/source/res/fb2edit.qrc @@ -9,6 +9,5 @@ <file>style.css</file> <file alias="ts/ru.qm">../ts/ru.qm</file> <file alias="js/jquery.js">../../3rdparty/jQuery/jquery.js</file> - <file>dots.png</file> </qresource> </RCC> |