Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lintest/fb2edit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKandrashin Denis <mail@lintest.ru>2012-11-06 23:00:18 +0400
committerKandrashin Denis <mail@lintest.ru>2012-11-06 23:00:18 +0400
commit92ac216f8ca4d2372f411ed9484699f0e55790a7 (patch)
tree84d552a94e02f0647948d4ccac14ab8c4e6b9cda
parentb7c7ae0d27dcb56d8f3e3aced2168ac6e7eed3e2 (diff)
New class: FbComboCtrl
-rw-r--r--fb2edit.pro1
-rw-r--r--source/fb2dlgs.cpp100
-rw-r--r--source/fb2dlgs.hpp21
-rw-r--r--source/fb2save.cpp1
-rw-r--r--source/res/dots.pngbin182 -> 0 bytes
5 files changed, 75 insertions, 48 deletions
diff --git a/fb2edit.pro b/fb2edit.pro
index d5c3671..ddf7182 100644
--- a/fb2edit.pro
+++ b/fb2edit.pro
@@ -52,7 +52,6 @@ QT += network
QT += xmlpatterns
OTHER_FILES += \
- source/res/dots.png \
source/res/style.css \
source/res/blank.fb2 \
source/js/export.js \
diff --git a/source/fb2dlgs.cpp b/source/fb2dlgs.cpp
index f06c2ff..7b240a5 100644
--- a/source/fb2dlgs.cpp
+++ b/source/fb2dlgs.cpp
@@ -168,11 +168,42 @@ FbSetupDlg::FbSetupDlg(QWidget *parent)
}
//---------------------------------------------------------------------------
+// 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()));
+ QVBoxLayout *layout = new QVBoxLayout(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)
+FbImageDlg::FbTab::FbTab(QWidget* parent, QAbstractItemModel *model)
: QWidget(parent)
+ , combo(0)
+ , edit(0)
{
QGridLayout * layout = new QGridLayout(this);
@@ -180,10 +211,17 @@ FbImageDlg::FbTab::FbTab(QWidget* parent)
label->setText(tr("File name:"));
layout->addWidget(label, 0, 0, 1, 1);
- combo = new FbImageCombo(this);
+ QWidget *control;
+ if (model) {
+ control = combo = new QComboBox(this);
+ combo->setModel(model);
+ } else {
+ control = edit = new FbComboCtrl(this);
+ }
+
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- combo->setSizePolicy(sizePolicy);
- layout->addWidget(combo, 0, 1, 1, 1);
+ control->setSizePolicy(sizePolicy);
+ layout->addWidget(control, 0, 1, 1, 1);
QFrame *frame = new FbTextFrame(this);
frame->setMinimumSize(QSize(300, 200));
@@ -194,32 +232,6 @@ FbImageDlg::FbTab::FbTab(QWidget* parent)
}
//---------------------------------------------------------------------------
-// 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
//---------------------------------------------------------------------------
@@ -247,29 +259,22 @@ FbImageDlg::FbImageDlg(FbTextEdit *text)
QUrl url = text->url();
tabFile = new FbTab(notebook);
- tabFile->combo->setEditable(true);
+ tabFile->edit->setIcon(FbIcon("document-open"));
tabFile->preview->setHtml(QString(), url);
- connect(tabFile->combo, SIGNAL(popup()), tabFile->combo, SLOT(selectFile()));
+ 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);
+ tabPict = new FbTab(notebook, model);
tabPict->preview->setHtml(QString(), url);
- tabPict->combo->setModel(model);
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)));
- tabPict->combo->setFocus();
}
- QString style =
-// "QComboBox::drop-down{border:0px;margin:0px;}"
- "QComboBox::down-arrow{image:url(:dots.png);}";
- tabFile->combo->setStyleSheet(style);
-
- tabFile->combo->setFocus();
+ tabFile->edit->setFocus();
resize(minimumSizeHint());
}
@@ -281,6 +286,19 @@ void FbImageDlg::notebookChanged(int index)
}
}
+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();
diff --git a/source/fb2dlgs.hpp b/source/fb2dlgs.hpp
index 9a50479..7707c62 100644
--- a/source/fb2dlgs.hpp
+++ b/source/fb2dlgs.hpp
@@ -9,6 +9,7 @@ class FbTextBase;
class FbTextEdit;
QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
class QLabel;
class QLineEdit;
class QTabWidget;
@@ -79,16 +80,22 @@ private:
Ui::FbSetup * ui;
};
-class FbImageCombo : public QComboBox
+#include <QVBoxLayout>
+#include <QToolButton>
+#include <QLineEdit>
+
+class FbComboCtrl : public QLineEdit
{
Q_OBJECT
public:
- explicit FbImageCombo(QWidget *parent = 0): QComboBox(parent) {}
- void showPopup();
+ explicit FbComboCtrl(QWidget *parent = 0);
+ void setIcon(const QIcon &icon);
signals:
void popup();
-public slots:
- void selectFile();
+protected:
+ void resizeEvent(QResizeEvent* event);
+private:
+ QToolButton *button;
};
class FbImageDlg : public QDialog
@@ -99,9 +106,10 @@ private:
class FbTab: public QWidget
{
public:
- explicit FbTab(QWidget* parent);
+ explicit FbTab(QWidget* parent, QAbstractItemModel *model = 0);
QLabel *label;
QComboBox *combo;
+ FbComboCtrl *edit;
QWebView *preview;
};
@@ -111,6 +119,7 @@ public:
private slots:
void pictureActivated(const QString & text);
void notebookChanged(int index);
+ void selectFile();
private:
QTabWidget *notebook;
diff --git a/source/fb2save.cpp b/source/fb2save.cpp
index c9bd9fa..8089c45 100644
--- a/source/fb2save.cpp
+++ b/source/fb2save.cpp
@@ -393,6 +393,7 @@ FbSaveHandler::RootHandler::RootHandler(FbSaveWriter &writer, const QString &nam
FbXmlHandler::NodeHandler * FbSaveHandler::RootHandler::NewTag(const QString &name, const QXmlAttributes &atts)
{
+ Q_UNUSED(atts);
return name == "body" ? new BodyHandler(m_writer, name) : NULL;
}
diff --git a/source/res/dots.png b/source/res/dots.png
deleted file mode 100644
index 07c3838..0000000
--- a/source/res/dots.png
+++ /dev/null
Binary files differ