浏览代码

New dialog: FbImageDlg

Kandrashin Denis 12 年之前
父节点
当前提交
42148f6336
共有 5 个文件被更改,包括 106 次插入32 次删除
  1. 62 2
      source/fb2dlgs.cpp
  2. 25 2
      source/fb2dlgs.hpp
  3. 3 1
      source/fb2main.cpp
  4. 0 8
      source/fb2page.cpp
  5. 16 19
      source/fb2text.cpp

+ 62 - 2
source/fb2dlgs.cpp

@@ -9,7 +9,10 @@
 
 
 #include <QComboBox>
 #include <QComboBox>
 #include <QDialogButtonBox>
 #include <QDialogButtonBox>
+#include <QFrame>
+#include <QLabel>
 #include <QLineEdit>
 #include <QLineEdit>
+#include <QTabWidget>
 #include <QToolBar>
 #include <QToolBar>
 #include <QWebFrame>
 #include <QWebFrame>
 #include <QWebPage>
 #include <QWebPage>
@@ -156,9 +159,66 @@ void FbNoteDlg::loadFinished()
 //  FbSetupDlg
 //  FbSetupDlg
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 
 
-FbSetupDlg::FbSetupDlg(QWidget *parent, Qt::WindowFlags f)
-    : QDialog(parent, f)
+FbSetupDlg::FbSetupDlg(QWidget *parent)
+    : QDialog(parent)
     , ui(new Ui::FbSetup)
     , ui(new Ui::FbSetup)
 {
 {
     ui->setupUi(this);
     ui->setupUi(this);
 }
 }
+
+//---------------------------------------------------------------------------
+//  FbSetupDlg
+//---------------------------------------------------------------------------
+
+FbImageDlg::FbTab::FbTab(QWidget* parent)
+    : QWidget(parent)
+{
+    QGridLayout * layout = new QGridLayout(this);
+
+    label = new QLabel(this);
+    label->setText(tr("File name:"));
+    layout->addWidget(label, 0, 0, 1, 1);
+
+    combo = new QComboBox(this);
+    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+    combo->setSizePolicy(sizePolicy);
+    combo->setEditable(true);
+    layout->addWidget(combo, 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);
+    preview->load(QUrl("about:blank"));
+}
+
+FbImageDlg::FbImageDlg(QWidget *parent)
+    : QDialog(parent)
+{
+    setWindowTitle(tr("Insert picture"));
+
+    QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+
+    notebook = new QTabWidget(this);
+    notebook->addTab(tabPict = new FbTab(notebook), tr("Collection"));
+    notebook->addTab(tabFile = new FbTab(notebook), tr("New file"));
+    layout->addWidget(notebook);
+
+    QDialogButtonBox *buttons = new QDialogButtonBox(this);
+    buttons->setOrientation(Qt::Horizontal);
+    buttons->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
+    layout->addWidget(buttons);
+
+    QObject::connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
+    QObject::connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
+
+    resize(minimumSizeHint());
+
+    QString style =
+        "QComboBox::drop-down{border:0px;margin:0px;}"
+        "QComboBox::down-arrow {image:url(qrc:/dots.png);}";
+    tabFile->combo->setStyleSheet(style);
+    tabPict->combo->setFocus();
+}

+ 25 - 2
source/fb2dlgs.hpp

@@ -9,7 +9,9 @@ class FbTextEdit;
 
 
 QT_BEGIN_NAMESPACE
 QT_BEGIN_NAMESPACE
 class QComboBox;
 class QComboBox;
+class QLabel;
 class QLineEdit;
 class QLineEdit;
+class QTabWidget;
 class QToolBar;
 class QToolBar;
 class QWebView;
 class QWebView;
 QT_END_NAMESPACE
 QT_END_NAMESPACE
@@ -69,14 +71,35 @@ private:
 };
 };
 
 
 class FbSetupDlg : public QDialog
 class FbSetupDlg : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit FbSetupDlg(QWidget *parent = 0);
+private:
+    Ui::FbSetup * ui;
+};
+
+class FbImageDlg : public QDialog
 {
 {
     Q_OBJECT
     Q_OBJECT
 
 
+private:
+    class FbTab: public QWidget
+    {
+    public:
+        explicit FbTab(QWidget* parent);
+        QLabel *label;
+        QComboBox *combo;
+        QWebView *preview;
+    };
+
 public:
 public:
-    explicit FbSetupDlg(QWidget *parent = 0, Qt::WindowFlags f = 0);
+    explicit FbImageDlg(QWidget *parent = 0);
 
 
 private:
 private:
-    Ui::FbSetup * ui;
+    QTabWidget *notebook;
+    FbTab *tabPict;
+    FbTab *tabFile;
 };
 };
 
 
 #endif // FB2DLGS_H
 #endif // FB2DLGS_H

+ 3 - 1
source/fb2main.cpp

@@ -38,9 +38,11 @@ FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
     createStatusBar();
     createStatusBar();
     readSettings();
     readSettings();
 
 
+    QString filepath = filename.isEmpty() ? QString(":blank.fb2") : filename;
+
     mainDock->setMode(Fb::Text);
     mainDock->setMode(Fb::Text);
     setCurrentFile(filename);
     setCurrentFile(filename);
-    mainDock->load(filename);
+    mainDock->load(filepath);
 }
 }
 
 
 void FbMainWindow::logMessage(const QString &message)
 void FbMainWindow::logMessage(const QString &message)

+ 0 - 8
source/fb2page.cpp

@@ -43,17 +43,9 @@ FbTextPage::FbTextPage(QObject *parent)
 
 
     setContentEditable(true);
     setContentEditable(true);
     setNetworkAccessManager(new FbNetworkAccessManager(this));
     setNetworkAccessManager(new FbNetworkAccessManager(this));
-    connect(this, SIGNAL(linkHovered(QString,QString,QString)), parent, SLOT(linkHovered(QString,QString,QString)));
     connect(this, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
     connect(this, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
     connect(this, SIGNAL(contentsChanged()), SLOT(fixContents()));
     connect(this, SIGNAL(contentsChanged()), SLOT(fixContents()));
     connect(this, SIGNAL(selectionChanged()), SLOT(showStatus()));
     connect(this, SIGNAL(selectionChanged()), SLOT(showStatus()));
-
-    QFile *file = new QFile(":blank.fb2");
-    if (file->open(QFile::ReadOnly | QFile::Text)) {
-        read(file);
-    } else {
-        delete file;
-    }
 }
 }
 
 
 FbNetworkAccessManager *FbTextPage::temp()
 FbNetworkAccessManager *FbTextPage::temp()

+ 16 - 19
source/fb2text.cpp

@@ -215,9 +215,11 @@ FbTextEdit::FbTextEdit(QWidget *parent, QObject *owner)
     , dockImgs(0)
     , dockImgs(0)
     , dockInsp(0)
     , dockInsp(0)
 {
 {
+    FbTextPage * p = new FbTextPage(this);
     setContextMenuPolicy(Qt::CustomContextMenu);
     setContextMenuPolicy(Qt::CustomContextMenu);
     connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint)));
     connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint)));
-    setPage(new FbTextPage(this));
+    connect(p, SIGNAL(linkHovered(QString,QString,QString)), SLOT(linkHovered(QString,QString,QString)));
+    setPage(p);
 }
 }
 
 
 FbTextEdit::~FbTextEdit()
 FbTextEdit::~FbTextEdit()
@@ -262,6 +264,10 @@ void FbTextEdit::connectActions(QToolBar *tool)
 
 
     connect(act(Fb::EditFind), SIGNAL(triggered()), SLOT(find()));
     connect(act(Fb::EditFind), SIGNAL(triggered()), SLOT(find()));
 
 
+    connect(act(Fb::InsertImage), SIGNAL(triggered()), SLOT(insertImage()));
+    connect(act(Fb::InsertLink), SIGNAL(triggered()), SLOT(insertLink()));
+    connect(act(Fb::InsertNote), SIGNAL(triggered()), SLOT(insertNote()));
+
     connect(act(Fb::ViewContents), SIGNAL(triggered(bool)), SLOT(viewContents(bool)));
     connect(act(Fb::ViewContents), SIGNAL(triggered(bool)), SLOT(viewContents(bool)));
     connect(act(Fb::ViewPictures), SIGNAL(triggered(bool)), SLOT(viewPictures(bool)));
     connect(act(Fb::ViewPictures), SIGNAL(triggered(bool)), SLOT(viewPictures(bool)));
     connect(act(Fb::ViewInspector), SIGNAL(triggered(bool)), SLOT(viewInspector(bool)));
     connect(act(Fb::ViewInspector), SIGNAL(triggered(bool)), SLOT(viewInspector(bool)));
@@ -271,13 +277,6 @@ void FbTextEdit::connectActions(QToolBar *tool)
     connect(act(Fb::ZoomReset), SIGNAL(triggered()), SLOT(zoomReset()));
     connect(act(Fb::ZoomReset), SIGNAL(triggered()), SLOT(zoomReset()));
 
 
     /*
     /*
-    connect(textPage, SIGNAL(selectionChanged()), SLOT(selectionChanged()));
-
-    connect(actionFind, SIGNAL(triggered()), textEdit, SLOT(find()));
-    connect(actionImage, SIGNAL(triggered()), textEdit, SLOT(insertImage()));
-    connect(actionNote, SIGNAL(triggered()), textEdit, SLOT(insertNote()));
-    connect(actionLink, SIGNAL(triggered()), textEdit, SLOT(insertLink()));
-
     connect(actionTitle, SIGNAL(triggered()), textPage, SLOT(insertTitle()));
     connect(actionTitle, SIGNAL(triggered()), textPage, SLOT(insertTitle()));
     connect(actionAnnot, SIGNAL(triggered()), textPage, SLOT(insertAnnot()));
     connect(actionAnnot, SIGNAL(triggered()), textPage, SLOT(insertAnnot()));
     connect(actionAuthor, SIGNAL(triggered()), textPage, SLOT(insertAuthor()));
     connect(actionAuthor, SIGNAL(triggered()), textPage, SLOT(insertAuthor()));
@@ -289,15 +288,10 @@ void FbTextEdit::connectActions(QToolBar *tool)
     connect(actionDate, SIGNAL(triggered()), textPage, SLOT(insertDate()));
     connect(actionDate, SIGNAL(triggered()), textPage, SLOT(insertDate()));
     connect(actionBody, SIGNAL(triggered()), textPage, SLOT(insertBody()));
     connect(actionBody, SIGNAL(triggered()), textPage, SLOT(insertBody()));
 
 
-    connect(actionSimpleText, SIGNAL(triggered()), textPage, SLOT(insertText()));
-    connect(actionParaSeparator, SIGNAL(triggered()), textEdit->pageAction(QWebPage::InsertParagraphSeparator), SIGNAL(triggered()));
-    connect(actionLineSeparator, SIGNAL(triggered()), textEdit->pageAction(QWebPage::InsertLineSeparator), SIGNAL(triggered()));
-
     connect(actionSectionAdd, SIGNAL(triggered()), textPage, SLOT(createSection()));
     connect(actionSectionAdd, SIGNAL(triggered()), textPage, SLOT(createSection()));
     connect(actionSectionDel, SIGNAL(triggered()), textPage, SLOT(deleteSection()));
     connect(actionSectionDel, SIGNAL(triggered()), textPage, SLOT(deleteSection()));
     connect(actionTextTitle, SIGNAL(triggered()), textPage, SLOT(createTitle()));
     connect(actionTextTitle, SIGNAL(triggered()), textPage, SLOT(createTitle()));
-
-*/
+    */
 
 
     tool->clear();
     tool->clear();
 
 
@@ -588,11 +582,14 @@ void FbTextEdit::find()
 
 
 void FbTextEdit::insertImage()
 void FbTextEdit::insertImage()
 {
 {
+    FbImageDlg(this).exec();
+    return;
+
     QString filters;
     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("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 (*)");
     filters += tr("All Files (*)");
 
 
     QString path = QFileDialog::getOpenFileName(this, tr("Insert image..."), QString(), filters);
     QString path = QFileDialog::getOpenFileName(this, tr("Insert image..."), QString(), filters);
@@ -621,7 +618,7 @@ void FbTextEdit::insertLink()
 
 
 void FbTextEdit::execCommand(const QString &cmd, const QString &arg)
 void FbTextEdit::execCommand(const QString &cmd, const QString &arg)
 {
 {
-    QString javascript = QString("document.execCommand(\"%1\",false,\"%2\")").arg(cmd).arg(arg);
+    QString javascript = QString("document.exelayoutcCommand(\"%1\",false,\"%2\")").arg(cmd).arg(arg);
     page()->mainFrame()->evaluateJavaScript(javascript);
     page()->mainFrame()->evaluateJavaScript(javascript);
 }
 }