Expose QPixmapCache's cache limit size as an user preference
This commit is contained in:
parent
776d809f2f
commit
b96104bed4
6 changed files with 42 additions and 5 deletions
|
@ -50,16 +50,27 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
picDownloadHqCheckBox = new QCheckBox;
|
picDownloadHqCheckBox = new QCheckBox;
|
||||||
picDownloadHqCheckBox->setChecked(settingsCache->getPicDownloadHq());
|
picDownloadHqCheckBox->setChecked(settingsCache->getPicDownloadHq());
|
||||||
|
|
||||||
|
pixmapCacheLabel = new QLabel;
|
||||||
|
pixmapCacheEdit = new QSpinBox;
|
||||||
|
pixmapCacheEdit->setMinimum(64);
|
||||||
|
pixmapCacheEdit->setMaximum(8192);
|
||||||
|
pixmapCacheEdit->setSingleStep(64);
|
||||||
|
pixmapCacheEdit->setValue(settingsCache->getPixmapCacheSize());
|
||||||
|
pixmapCacheEdit->setSuffix(" MB");
|
||||||
|
|
||||||
connect(languageBox, SIGNAL(currentIndexChanged(int)), this, SLOT(languageBoxChanged(int)));
|
connect(languageBox, SIGNAL(currentIndexChanged(int)), this, SLOT(languageBoxChanged(int)));
|
||||||
connect(picDownloadCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPicDownload(int)));
|
connect(picDownloadCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPicDownload(int)));
|
||||||
connect(picDownloadHqCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPicDownloadHq(int)));
|
connect(picDownloadHqCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPicDownloadHq(int)));
|
||||||
|
connect(pixmapCacheEdit, SIGNAL(valueChanged(int)), settingsCache, SLOT(setPixmapCacheSize(int)));
|
||||||
|
|
||||||
QGridLayout *personalGrid = new QGridLayout;
|
QGridLayout *personalGrid = new QGridLayout;
|
||||||
personalGrid->addWidget(languageLabel, 0, 0);
|
personalGrid->addWidget(languageLabel, 0, 0);
|
||||||
personalGrid->addWidget(languageBox, 0, 1);
|
personalGrid->addWidget(languageBox, 0, 1);
|
||||||
personalGrid->addWidget(picDownloadCheckBox, 1, 0, 1, 2);
|
personalGrid->addWidget(pixmapCacheLabel, 1, 0, 1, 1);
|
||||||
personalGrid->addWidget(picDownloadHqCheckBox, 2, 0, 1, 2);
|
personalGrid->addWidget(pixmapCacheEdit, 1, 1, 1, 1);
|
||||||
personalGrid->addWidget(clearDownloadedPicsButton, 3, 0, 1, 1);
|
personalGrid->addWidget(picDownloadCheckBox, 2, 0, 1, 2);
|
||||||
|
personalGrid->addWidget(picDownloadHqCheckBox, 3, 0, 1, 2);
|
||||||
|
personalGrid->addWidget(clearDownloadedPicsButton, 4, 0, 1, 1);
|
||||||
|
|
||||||
personalGroupBox = new QGroupBox;
|
personalGroupBox = new QGroupBox;
|
||||||
personalGroupBox->setLayout(personalGrid);
|
personalGroupBox->setLayout(personalGrid);
|
||||||
|
@ -227,6 +238,7 @@ void GeneralSettingsPage::retranslateUi()
|
||||||
picsPathLabel->setText(tr("Pictures directory:"));
|
picsPathLabel->setText(tr("Pictures directory:"));
|
||||||
cardDatabasePathLabel->setText(tr("Card database:"));
|
cardDatabasePathLabel->setText(tr("Card database:"));
|
||||||
tokenDatabasePathLabel->setText(tr("Token database:"));
|
tokenDatabasePathLabel->setText(tr("Token database:"));
|
||||||
|
pixmapCacheLabel->setText(tr("Picture cache size:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
AppearanceSettingsPage::AppearanceSettingsPage()
|
AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
|
|
|
@ -16,6 +16,7 @@ class QLabel;
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
class QRadioButton;
|
class QRadioButton;
|
||||||
|
class QSpinBox;
|
||||||
|
|
||||||
class AbstractSettingsPage : public QWidget {
|
class AbstractSettingsPage : public QWidget {
|
||||||
public:
|
public:
|
||||||
|
@ -39,11 +40,12 @@ private:
|
||||||
QStringList findQmFiles();
|
QStringList findQmFiles();
|
||||||
QString languageName(const QString &qmFile);
|
QString languageName(const QString &qmFile);
|
||||||
QLineEdit *deckPathEdit, *replaysPathEdit, *picsPathEdit, *cardDatabasePathEdit, *tokenDatabasePathEdit;
|
QLineEdit *deckPathEdit, *replaysPathEdit, *picsPathEdit, *cardDatabasePathEdit, *tokenDatabasePathEdit;
|
||||||
|
QSpinBox *pixmapCacheEdit;
|
||||||
QGroupBox *personalGroupBox, *pathsGroupBox;
|
QGroupBox *personalGroupBox, *pathsGroupBox;
|
||||||
QComboBox *languageBox;
|
QComboBox *languageBox;
|
||||||
QCheckBox *picDownloadCheckBox;
|
QCheckBox *picDownloadCheckBox;
|
||||||
QCheckBox *picDownloadHqCheckBox;
|
QCheckBox *picDownloadHqCheckBox;
|
||||||
QLabel *languageLabel, *deckPathLabel, *replaysPathLabel, *picsPathLabel, *cardDatabasePathLabel, *tokenDatabasePathLabel;
|
QLabel *languageLabel, *deckPathLabel, *replaysPathLabel, *picsPathLabel, *cardDatabasePathLabel, *tokenDatabasePathLabel, *pixmapCacheLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AppearanceSettingsPage : public AbstractSettingsPage {
|
class AppearanceSettingsPage : public AbstractSettingsPage {
|
||||||
|
|
|
@ -23,6 +23,7 @@ SettingsCache::SettingsCache()
|
||||||
|
|
||||||
picDownload = settings->value("personal/picturedownload", true).toBool();
|
picDownload = settings->value("personal/picturedownload", true).toBool();
|
||||||
picDownloadHq = settings->value("personal/picturedownloadhq", false).toBool();
|
picDownloadHq = settings->value("personal/picturedownloadhq", false).toBool();
|
||||||
|
pixmapCacheSize = settings->value("personal/pixmapCacheSize", PIXMAPCACHE_SIZE_DEFAULT).toInt();
|
||||||
picUrl = settings->value("personal/picUrl", PIC_URL_DEFAULT).toString();
|
picUrl = settings->value("personal/picUrl", PIC_URL_DEFAULT).toString();
|
||||||
picUrlHq = settings->value("personal/picUrlHq", PIC_URL_HQ_DEFAULT).toString();
|
picUrlHq = settings->value("personal/picUrlHq", PIC_URL_HQ_DEFAULT).toString();
|
||||||
picUrlFallback = settings->value("personal/picUrlFallback", PIC_URL_FALLBACK).toString();
|
picUrlFallback = settings->value("personal/picUrlFallback", PIC_URL_FALLBACK).toString();
|
||||||
|
@ -289,6 +290,13 @@ void SettingsCache::setAutoConnect(const bool &_autoConnect)
|
||||||
settings->setValue("server/auto_connect", attemptAutoConnect ? 1 : 0);
|
settings->setValue("server/auto_connect", attemptAutoConnect ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsCache::setPixmapCacheSize(const int _pixmapCacheSize)
|
||||||
|
{
|
||||||
|
pixmapCacheSize = _pixmapCacheSize;
|
||||||
|
settings->setValue("personal/pixmapCacheSize", pixmapCacheSize);
|
||||||
|
emit pixmapCacheSizeChanged(pixmapCacheSize);
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsCache::copyPath(const QString &src, const QString &dst)
|
void SettingsCache::copyPath(const QString &src, const QString &dst)
|
||||||
{
|
{
|
||||||
// test source && return if inexistent
|
// test source && return if inexistent
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#define PIC_URL_FALLBACK "http://mtgimage.com/set/!setcode!/!name!.jpg"
|
#define PIC_URL_FALLBACK "http://mtgimage.com/set/!setcode!/!name!.jpg"
|
||||||
#define PIC_URL_HQ_DEFAULT "http://mtgimage.com/multiverseid/!cardid!.jpg"
|
#define PIC_URL_HQ_DEFAULT "http://mtgimage.com/multiverseid/!cardid!.jpg"
|
||||||
#define PIC_URL_HQ_FALLBACK "http://mtgimage.com/set/!setcode!/!name!.jpg"
|
#define PIC_URL_HQ_FALLBACK "http://mtgimage.com/set/!setcode!/!name!.jpg"
|
||||||
|
// size should be a multiple of 64
|
||||||
|
#define PIXMAPCACHE_SIZE_DEFAULT 256
|
||||||
|
|
||||||
class QSettings;
|
class QSettings;
|
||||||
|
|
||||||
|
@ -32,6 +34,7 @@ signals:
|
||||||
void soundPathChanged();
|
void soundPathChanged();
|
||||||
void priceTagFeatureChanged(int enabled);
|
void priceTagFeatureChanged(int enabled);
|
||||||
void ignoreUnregisteredUsersChanged();
|
void ignoreUnregisteredUsersChanged();
|
||||||
|
void pixmapCacheSizeChanged(int value);
|
||||||
private:
|
private:
|
||||||
QSettings *settings;
|
QSettings *settings;
|
||||||
|
|
||||||
|
@ -62,6 +65,7 @@ private:
|
||||||
QString picUrlFallback;
|
QString picUrlFallback;
|
||||||
QString picUrlHqFallback;
|
QString picUrlHqFallback;
|
||||||
bool attemptAutoConnect;
|
bool attemptAutoConnect;
|
||||||
|
int pixmapCacheSize;
|
||||||
public:
|
public:
|
||||||
SettingsCache();
|
SettingsCache();
|
||||||
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
|
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
|
||||||
|
@ -101,6 +105,7 @@ public:
|
||||||
QString getPicUrlHqFallback() const { return picUrlHqFallback; }
|
QString getPicUrlHqFallback() const { return picUrlHqFallback; }
|
||||||
void copyPath(const QString &src, const QString &dst);
|
void copyPath(const QString &src, const QString &dst);
|
||||||
bool getAutoConnect() const { return attemptAutoConnect; }
|
bool getAutoConnect() const { return attemptAutoConnect; }
|
||||||
|
int getPixmapCacheSize() const { return pixmapCacheSize; }
|
||||||
public slots:
|
public slots:
|
||||||
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
|
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
|
||||||
void setLang(const QString &_lang);
|
void setLang(const QString &_lang);
|
||||||
|
@ -138,6 +143,7 @@ public slots:
|
||||||
void setPicUrlFallback(const QString &_picUrlFallback);
|
void setPicUrlFallback(const QString &_picUrlFallback);
|
||||||
void setPicUrlHqFallback(const QString &_picUrlHqFallback);
|
void setPicUrlHqFallback(const QString &_picUrlHqFallback);
|
||||||
void setAutoConnect(const bool &_autoConnect);
|
void setAutoConnect(const bool &_autoConnect);
|
||||||
|
void setPixmapCacheSize(const int _pixmapCacheSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SettingsCache *settingsCache;
|
extern SettingsCache *settingsCache;
|
||||||
|
|
|
@ -361,7 +361,8 @@ void MainWindow::createMenus()
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent), localServer(0), bHasActivated(false)
|
: QMainWindow(parent), localServer(0), bHasActivated(false)
|
||||||
{
|
{
|
||||||
QPixmapCache::setCacheLimit(200000);
|
connect(settingsCache, SIGNAL(pixmapCacheSizeChanged(int)), this, SLOT(pixmapCacheSizeChanged(int)));
|
||||||
|
pixmapCacheSizeChanged(settingsCache->getPixmapCacheSize());
|
||||||
|
|
||||||
client = new RemoteClient;
|
client = new RemoteClient;
|
||||||
connect(client, SIGNAL(connectionClosedEventReceived(const Event_ConnectionClosed &)), this, SLOT(processConnectionClosedEvent(const Event_ConnectionClosed &)));
|
connect(client, SIGNAL(connectionClosedEventReceived(const Event_ConnectionClosed &)), this, SLOT(processConnectionClosedEvent(const Event_ConnectionClosed &)));
|
||||||
|
@ -430,3 +431,10 @@ void MainWindow::changeEvent(QEvent *event)
|
||||||
|
|
||||||
QMainWindow::changeEvent(event);
|
QMainWindow::changeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::pixmapCacheSizeChanged(int value)
|
||||||
|
{
|
||||||
|
//qDebug() << "Setting pixmap cache size to " << value << " MBs";
|
||||||
|
// translate MBs to KBs
|
||||||
|
QPixmapCache::setCacheLimit(value * 1024);
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ private slots:
|
||||||
void protocolVersionMismatch(int localVersion, int remoteVersion);
|
void protocolVersionMismatch(int localVersion, int remoteVersion);
|
||||||
void userInfoReceived(const ServerInfo_User &userInfo);
|
void userInfoReceived(const ServerInfo_User &userInfo);
|
||||||
void localGameEnded();
|
void localGameEnded();
|
||||||
|
void pixmapCacheSizeChanged(int value);
|
||||||
|
|
||||||
void actConnect();
|
void actConnect();
|
||||||
void actDisconnect();
|
void actDisconnect();
|
||||||
|
|
Loading…
Reference in a new issue