Skip to content

Commit

Permalink
Load plugins only once
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Mar 14, 2016
1 parent 994a568 commit 1fd7370
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 59 deletions.
6 changes: 3 additions & 3 deletions src/gui/clipboardbrowser.cpp
Expand Up @@ -171,17 +171,17 @@ void ClipboardBrowserShared::loadFromConfiguration()
minutesToExpire = appConfig.option<Config::expire_tab>();
}

ClipboardBrowser::ClipboardBrowser(QWidget *parent, const ClipboardBrowserSharedPtr &sharedData)
ClipboardBrowser::ClipboardBrowser(const ClipboardBrowserSharedPtr &sharedData, QWidget *parent)
: QListView(parent)
, m_itemLoader(NULL)
, m_tabName()
, m_lastFiltered(-1)
, m(this)
, d(this, sharedData ? sharedData->itemFactory : NULL)
, d(this, sharedData->itemFactory)
, m_invalidateCache(false)
, m_expireAfterEditing(false)
, m_editor(NULL)
, m_sharedData(sharedData ? sharedData : ClipboardBrowserSharedPtr(new ClipboardBrowserShared))
, m_sharedData(sharedData)
, m_loadButton(NULL)
, m_searchProgress(NULL)
, m_dragTargetRow(-1)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/clipboardbrowser.h
Expand Up @@ -48,7 +48,7 @@ Q_DECLARE_FLAGS(SelectActions, SelectAction)
Q_DECLARE_OPERATORS_FOR_FLAGS(SelectActions)

struct ClipboardBrowserShared {
explicit ClipboardBrowserShared(ItemFactory *itemFactory = NULL);
explicit ClipboardBrowserShared(ItemFactory *itemFactory);

void loadFromConfiguration();

Expand Down Expand Up @@ -84,7 +84,7 @@ class ClipboardBrowser : public QListView
QPointer<ClipboardBrowser> c;
};

explicit ClipboardBrowser(QWidget *parent = NULL, const ClipboardBrowserSharedPtr &sharedData = ClipboardBrowserSharedPtr());
explicit ClipboardBrowser(const ClipboardBrowserSharedPtr &sharedData, QWidget *parent = NULL);
/** Close all external editors and save items if needed. */
~ClipboardBrowser();
/** Load settings. */
Expand Down
83 changes: 47 additions & 36 deletions src/gui/configtabappearance.cpp
Expand Up @@ -53,43 +53,10 @@ ConfigTabAppearance::ConfigTabAppearance(QWidget *parent)
, ui(new Ui::ConfigTabAppearance)
, m_theme(ui)
, m_editor()
, m_preview(NULL)
{
ui->setupUi(this);

const QString searchFor = tr("item", "Search expression in preview in Appearance tab.");

ClipboardBrowser *c = ui->clipboardBrowserPreview;
c->addItems( QStringList()
<< tr("Search string is %1.").arg( quoteString(searchFor) )
<< tr("Select an item and\n"
"press F2 to edit.")
<< tr("Select items and move them with\n"
"CTRL and up or down key.")
<< tr("Remove item with Delete key.") );
for (int i = 1; i <= 20; ++i)
c->add( tr("Example item %1").arg(i), -1 );

QAbstractItemModel *model = c->model();
QModelIndex index = model->index(0, 0);
QVariantMap dataMap;
dataMap.insert( mimeItemNotes, tr("Some random notes (Shift+F2 to edit)").toUtf8() );
model->setData(index, dataMap, contentType::updateData);

// Highlight found text but don't filter out any items.
c->filterItems( QRegExp(QString("|") + searchFor, Qt::CaseInsensitive) );

QAction *act;

act = new QAction(c);
act->setShortcut( QString("Shift+F2") );
connect(act, SIGNAL(triggered()), c, SLOT(editNotes()));
c->addAction(act);

act = new QAction(c);
act->setShortcut( QString("F2") );
connect(act, SIGNAL(triggered()), c, SLOT(editSelected()));
c->addAction(act);

// Connect signals from theme buttons.
foreach (QPushButton *button, ui->scrollAreaTheme->findChildren<QPushButton *>()) {
if (button->objectName().endsWith("Font"))
Expand Down Expand Up @@ -128,6 +95,50 @@ void ConfigTabAppearance::saveTheme(QSettings &settings)
updateThemes();
}

void ConfigTabAppearance::createPreview(ItemFactory *itemFactory)
{
if (m_preview)
return;

ClipboardBrowserSharedPtr sharedData(new ClipboardBrowserShared(itemFactory));
ClipboardBrowser *c = new ClipboardBrowser(sharedData, this);
ui->browserParentLayout->addWidget(c);
m_preview = c;

const QString searchFor = tr("item", "Search expression in preview in Appearance tab.");

c->addItems( QStringList()
<< tr("Search string is %1.").arg( quoteString(searchFor) )
<< tr("Select an item and\n"
"press F2 to edit.")
<< tr("Select items and move them with\n"
"CTRL and up or down key.")
<< tr("Remove item with Delete key.") );
for (int i = 1; i <= 20; ++i)
c->add( tr("Example item %1").arg(i), -1 );

QAbstractItemModel *model = c->model();
QModelIndex index = model->index(0, 0);
QVariantMap dataMap;
dataMap.insert( mimeItemNotes, tr("Some random notes (Shift+F2 to edit)").toUtf8() );
model->setData(index, dataMap, contentType::updateData);

// Highlight found text but don't filter out any items.
c->filterItems( QRegExp(QString("|") + searchFor, Qt::CaseInsensitive) );

QAction *act;

act = new QAction(c);
act->setShortcut( QString("Shift+F2") );
connect(act, SIGNAL(triggered()), c, SLOT(editNotes()));
c->addAction(act);

act = new QAction(c);
act->setShortcut( QString("F2") );
connect(act, SIGNAL(triggered()), c, SLOT(editSelected()));
c->addAction(act);
}

void ConfigTabAppearance::onFontButtonClicked()
{
Q_ASSERT(sender() != NULL);
Expand Down Expand Up @@ -450,6 +461,6 @@ QIcon ConfigTabAppearance::createThemeIcon(const QString &fileName)

void ConfigTabAppearance::decoratePreview()
{
if ( isVisible() )
ui->clipboardBrowserPreview->decorate(m_theme);
if ( m_preview && isVisible() )
m_preview->decorate(m_theme);
}
5 changes: 5 additions & 0 deletions src/gui/configtabappearance.h
Expand Up @@ -31,6 +31,7 @@ class ConfigTabAppearance;

class ClipboardBrowser;
class ItemDelegate;
class ItemFactory;
class Option;
class QAbstractScrollArea;
class QSettings;
Expand All @@ -50,6 +51,8 @@ class ConfigTabAppearance : public QWidget

void setEditor(const QString &editor) { m_editor = editor; }

void createPreview(ItemFactory *itemFactory);

protected:
void showEvent(QShowEvent *event);

Expand Down Expand Up @@ -88,6 +91,8 @@ private slots:
Ui::ConfigTabAppearance *ui;
Theme m_theme;
QString m_editor;

ClipboardBrowser *m_preview;
};

#endif // CONFIGTABAPPEARANCE_H
2 changes: 2 additions & 0 deletions src/gui/configurationmanager.cpp
Expand Up @@ -108,6 +108,8 @@ ConfigurationManager::ConfigurationManager(ItemFactory *itemFactory, QWidget *pa
connect( ui->configTabShortcuts, SIGNAL(openCommandDialogRequest()),
this, SIGNAL(openCommandDialogRequest()));

ui->configTabAppearance->createPreview(itemFactory);

loadSettings();
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/mainwindow.cpp
Expand Up @@ -998,7 +998,7 @@ ClipboardBrowser *MainWindow::createTab(
if (i != -1)
return getBrowser(i);

ClipboardBrowser *c = new ClipboardBrowser(this, m_sharedData);
ClipboardBrowser *c = new ClipboardBrowser(m_sharedData, this);
c->setTabName(name);
c->loadSettings();

Expand Down
2 changes: 2 additions & 0 deletions src/gui/theme.cpp
Expand Up @@ -21,6 +21,8 @@

#include "ui_configtabappearance.h"

#include "item/itemdelegate.h"

#include "gui/iconfont.h"

#include <QListView>
Expand Down
2 changes: 1 addition & 1 deletion src/item/itemdelegate.cpp
Expand Up @@ -53,7 +53,7 @@ int itemMargin()
ItemDelegate::ItemDelegate(QAbstractItemView *view, ItemFactory *itemFactory, QWidget *parent)
: QItemDelegate(parent)
, m_view(view)
, m_itemFactory(itemFactory ? itemFactory : new ItemFactory(this))
, m_itemFactory(itemFactory)
, m_saveOnReturnKey(true)
, m_re()
, m_maxSize(2048, 2048 * 8)
Expand Down
18 changes: 2 additions & 16 deletions src/ui/configtabappearance.ui
Expand Up @@ -34,7 +34,7 @@
<x>0</x>
<y>0</y>
<width>281</width>
<height>488</height>
<height>482</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
Expand Down Expand Up @@ -383,7 +383,7 @@
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7" stretch="0,1">
<layout class="QVBoxLayout" name="browserParentLayout" stretch="0">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -392,27 +392,13 @@
<property name="text">
<string>Preview:</string>
</property>
<property name="buddy">
<cstring>clipboardBrowserPreview</cstring>
</property>
</widget>
</item>
<item>
<widget class="ClipboardBrowser" name="clipboardBrowserPreview"/>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ClipboardBrowser</class>
<extends>QListView</extends>
<header>gui/clipboardbrowser.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>clipboardBrowserPreview</tabstop>
<tabstop>pushButtonColorBg</tabstop>
<tabstop>pushButtonColorFg</tabstop>
<tabstop>pushButtonFont</tabstop>
Expand Down

0 comments on commit 1fd7370

Please sign in to comment.