Browse Source

Select image file

Kandrashin Denis 12 years ago
parent
commit
b7c7ae0d27
2 changed files with 44 additions and 6 deletions
  1. 31 3
      source/fb2dlgs.cpp
  2. 13 3
      source/fb2dlgs.hpp

+ 31 - 3
source/fb2dlgs.cpp

@@ -9,6 +9,7 @@
 
 #include <QComboBox>
 #include <QDialogButtonBox>
+#include <QFileDialog>
 #include <QFrame>
 #include <QLabel>
 #include <QLineEdit>
@@ -179,7 +180,7 @@ FbImageDlg::FbTab::FbTab(QWidget* parent)
     label->setText(tr("File name:"));
     layout->addWidget(label, 0, 0, 1, 1);
 
-    combo = new QComboBox(this);
+    combo = new FbImageCombo(this);
     QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     combo->setSizePolicy(sizePolicy);
     layout->addWidget(combo, 0, 1, 1, 1);
@@ -192,6 +193,32 @@ FbImageDlg::FbTab::FbTab(QWidget* parent)
     frame->layout()->addWidget(preview);
 }
 
+//---------------------------------------------------------------------------
+//  FbImageCombo
+//---------------------------------------------------------------------------
+
+void FbImageCombo::showPopup()
+{
+    QComboBox::showPopup();
+    if (isEditable()) {
+        emit popup();
+        QComboBox::hidePopup();
+    }
+}
+
+void FbImageCombo::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 (*)");
+
+    QString path = QFileDialog::getOpenFileName(this, tr("Insert image..."), QString(), filters);
+    if (!path.isEmpty()) setEditText(path);
+}
+
 //---------------------------------------------------------------------------
 //  FbImageDlg
 //---------------------------------------------------------------------------
@@ -222,7 +249,8 @@ FbImageDlg::FbImageDlg(FbTextEdit *text)
     tabFile = new FbTab(notebook);
     tabFile->combo->setEditable(true);
     tabFile->preview->setHtml(QString(), url);
-    notebook->addTab(tabFile, tr("New file"));
+    connect(tabFile->combo, SIGNAL(popup()), tabFile->combo, SLOT(selectFile()));
+    notebook->addTab(tabFile, tr("Select file"));
 
     if (text->store()->count()) {
         FbListModel *model = new FbListModel(text, this);
@@ -231,7 +259,7 @@ FbImageDlg::FbImageDlg(FbTextEdit *text)
         tabPict->combo->setModel(model);
         tabPict->combo->setCurrentIndex(0);
         tabPict->preview->page()->setNetworkAccessManager(text->page()->networkAccessManager());
-        notebook->addTab(tabPict, tr("Collection"));
+        notebook->addTab(tabPict, tr("From collection"));
         connect(tabPict->combo, SIGNAL(activated(QString)), SLOT(pictureActivated(QString)));
         tabPict->combo->setFocus();
     }

+ 13 - 3
source/fb2dlgs.hpp

@@ -2,13 +2,13 @@
 #define FB2DLGS_H
 
 #include <QDialog>
+#include <QComboBox>
 
 class FbCodeEdit;
 class FbTextBase;
 class FbTextEdit;
 
 QT_BEGIN_NAMESPACE
-class QComboBox;
 class QLabel;
 class QLineEdit;
 class QTabWidget;
@@ -21,8 +21,6 @@ class FbFind;
 class FbSetup;
 }
 
-
-
 class FbCodeFindDlg : public QDialog
 {
     Q_OBJECT
@@ -81,6 +79,18 @@ private:
     Ui::FbSetup * ui;
 };
 
+class FbImageCombo : public QComboBox
+{
+    Q_OBJECT
+public:
+    explicit FbImageCombo(QWidget *parent = 0): QComboBox(parent) {}
+    void showPopup();
+signals:
+    void popup();
+public slots:
+    void selectFile();
+};
+
 class FbImageDlg : public QDialog
 {
     Q_OBJECT