Skip to content

Commit

Permalink
change theme, dark mode initial connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Aug 28, 2019
1 parent 229a59f commit cacce31
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/qt/guiutil.cpp
Expand Up @@ -833,7 +833,7 @@ bool isExternal(QString theme)
if (theme.isEmpty())
return false;

return (theme.operator!=("default"));
return (theme.operator!=("default") && theme.operator!=("default-dark"));
}

// Open CSS when configured
Expand Down
3 changes: 1 addition & 2 deletions src/qt/pivx.qrc
Expand Up @@ -68,7 +68,7 @@
</qresource>
<qresource prefix="/css">
<file>res/css/default.css</file>
<file>pivx/res/css/style_dark.css</file>
<file alias="default-dark">pivx/res/css/style_dark.css</file>
<file alias="default">pivx/res/css/style_light.css</file>
</qresource>
<qresource prefix="/images">
Expand Down Expand Up @@ -285,6 +285,5 @@
<file alias="ic-check-box-indeterminate">pivx/res/img/ic-check-box-indeterminate.svg</file>
<file alias="ic-check-liliac-indeterminate">pivx/res/img/ic-check-liliac-indeterminate.svg</file>
<file alias="ani-loading">pivx/res/img/ani-loading.gif</file>

</qresource>
</RCC>
4 changes: 2 additions & 2 deletions src/qt/pivx/PIVXGUI.cpp
Expand Up @@ -174,6 +174,7 @@ void PIVXGUI::connectActions() {
});

connect(topBar, &TopBar::showHide, this, &PIVXGUI::showHide);
connect(topBar, &TopBar::changeTheme, this, &PIVXGUI::changeTheme);
connect(settingsWidget, &SettingsWidget::showHide, this, &PIVXGUI::showHide);
connect(sendWidget, &SendWidget::showHide, this, &PIVXGUI::showHide);
connect(receiveWidget, &ReceiveWidget::showHide, this, &PIVXGUI::showHide);
Expand Down Expand Up @@ -432,9 +433,8 @@ void PIVXGUI::showTop(QWidget* view){
}

void PIVXGUI::changeTheme(bool isLightTheme){
// Change theme in all of the childs here..

QString css = isLightTheme ? getLightTheme() : getDarkTheme();
QString css = GUIUtil::loadStyleSheet();
this->setStyleSheet(css);

// Notify
Expand Down
5 changes: 0 additions & 5 deletions src/qt/pivx/addresseswidget.cpp
Expand Up @@ -147,8 +147,6 @@ AddressesWidget::AddressesWidget(PIVXGUI* _window, QWidget *parent) :

connect(ui->listAddresses, SIGNAL(clicked(QModelIndex)), this, SLOT(handleAddressClicked(QModelIndex)));
connect(ui->btnSave, SIGNAL(clicked()), this, SLOT(onStoreContactClicked()));
// style
connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(changeTheme(bool, QString&)));
}

void AddressesWidget::handleAddressClicked(const QModelIndex &index){
Expand Down Expand Up @@ -270,10 +268,7 @@ void AddressesWidget::onCopyClicked(){
}

void AddressesWidget::changeTheme(bool isLightTheme, QString& theme){
// Change theme in all of the childs here..
this->setStyleSheet(theme);
static_cast<ContactsHolder*>(this->delegate->getRowFactory())->isLightTheme = isLightTheme;
updateStyle(this);
}

AddressesWidget::~AddressesWidget(){
Expand Down
7 changes: 0 additions & 7 deletions src/qt/pivx/dashboardwidget.cpp
Expand Up @@ -172,10 +172,6 @@ DashboardWidget::DashboardWidget(PIVXGUI* _window, QWidget *parent) :
setShadow(ui->layoutShadow);

connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex)));

// Style
connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(changeTheme(bool, QString&)));

}

void DashboardWidget::handleTransactionClicked(const QModelIndex &index){
Expand Down Expand Up @@ -344,11 +340,8 @@ void DashboardWidget::onSortChanged(const QString& value){
}

void DashboardWidget::changeTheme(bool isLightTheme, QString& theme){
// Change theme in all of the childs here..
this->setStyleSheet(theme);
static_cast<TxViewHolder*>(this->txViewDelegate->getRowFactory())->isLightTheme = isLightTheme;
this->changeChartColors();
updateStyle(this);
}

DashboardWidget::~DashboardWidget()
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/dashboardwidget.h
Expand Up @@ -59,7 +59,7 @@ class DashboardWidget : public PWidget
private slots:
void handleTransactionClicked(const QModelIndex &index);

void changeTheme(bool isLightTheme, QString &theme);
void changeTheme(bool isLightTheme, QString &theme) override;
void changeChartColors();
void onSortTxPressed();
void onSortChanged(const QString&);
Expand Down
5 changes: 0 additions & 5 deletions src/qt/pivx/privacywidget.cpp
Expand Up @@ -156,9 +156,6 @@ PrivacyWidget::PrivacyWidget(PIVXGUI* _window, QWidget *parent) :

connect(ui->pushLeft, &QPushButton::clicked, [this](){onMintSelected(false);});
connect(ui->pushRight, &QPushButton::clicked, [this](){onMintSelected(true);});
// Style
connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(changeTheme(bool, QString&)));


// List
ui->listView->setProperty("cssClass", "container");
Expand Down Expand Up @@ -463,10 +460,8 @@ void PrivacyWidget::updateDenomsSupply(){

void PrivacyWidget::changeTheme(bool isLightTheme, QString& theme){
// Change theme in all of the childs here..
this->setStyleSheet(theme);
static_cast<TxViewHolder*>(this->delegate->getRowFactory())->isLightTheme = isLightTheme;
ui->listView->update();
updateStyle(this);
}

PrivacyWidget::~PrivacyWidget()
Expand Down
9 changes: 7 additions & 2 deletions src/qt/pivx/pwidget.cpp
Expand Up @@ -6,7 +6,7 @@
PWidget::PWidget(PIVXGUI* _window, QWidget *parent) : QWidget(parent), window(_window)
{
if(window)
connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(changeTheme(bool, QString&)));
connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(onChangeTheme(bool, QString&)));
}

void PWidget::setClientModel(ClientModel* model){
Expand All @@ -19,9 +19,10 @@ void PWidget::setWalletModel(WalletModel* model){
loadWalletModel();
}

void PWidget::changeTheme(bool isLightTheme, QString& theme){
void PWidget::onChangeTheme(bool isLightTheme, QString& theme){
// Change theme in all of the childs here..
this->setStyleSheet(theme);
changeTheme(isLightTheme, theme);
updateStyle(this);
}

Expand Down Expand Up @@ -52,3 +53,7 @@ void PWidget::loadClientModel(){
void PWidget::loadWalletModel(){
// override
}

void PWidget::changeTheme(bool isLightTheme, QString& theme){
// override
}
3 changes: 2 additions & 1 deletion src/qt/pivx/pwidget.h
Expand Up @@ -28,7 +28,8 @@ class PWidget : public QWidget
bool execDialog(QDialog *dialog, int xDiv = 3, int yDiv = 5);

protected slots:
void changeTheme(bool isLightTheme, QString &theme);
virtual void changeTheme(bool isLightTheme, QString &theme);
void onChangeTheme(bool isLightTheme, QString &theme);

protected:
PIVXGUI* window = nullptr;
Expand Down
9 changes: 4 additions & 5 deletions src/qt/pivx/qtutils.cpp
Expand Up @@ -140,10 +140,7 @@ QSettings *settings = nullptr;

QSettings* getSettings(){
if(!settings){
QString m_path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
QString m_filename = "pivx_new_gui_config.ini" ;
settings = new QSettings(m_path + "/"+ m_filename,QSettings::IniFormat);

settings = new QSettings();
// Setup initial values if them are not there
setupSettings(settings);
}
Expand All @@ -156,7 +153,9 @@ bool isLightTheme(){
}

void setTheme(bool isLight){
getSettings()->setValue("lightTheme", isLight);
QSettings* settings = getSettings();
settings->setValue("theme", isLight ? "default" : "default-dark");
settings->setValue("lightTheme", isLight);
}


Expand Down
41 changes: 25 additions & 16 deletions src/qt/pivx/receivewidget.cpp
Expand Up @@ -142,7 +142,6 @@ ReceiveWidget::ReceiveWidget(PIVXGUI* _window, QWidget *parent) :
ui->listViewAddress->setVisible(false);

// Connect
connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(changeTheme(bool, QString&)));
connect(ui->pushButtonLabel, SIGNAL(clicked()), this, SLOT(onLabelClicked()));
connect(ui->pushButtonCopy, SIGNAL(clicked()), this, SLOT(onCopyClicked()));
connect(ui->pushButtonNewAddress, SIGNAL(clicked()), this, SLOT(onNewAddressClicked()));
Expand All @@ -166,14 +165,20 @@ void ReceiveWidget::loadWalletModel(){
}

void ReceiveWidget::refreshView(QString refreshAddress){
QString latestAddress = (refreshAddress.isEmpty()) ? this->addressTableModel->getLastUnusedAddress() : refreshAddress;
if (latestAddress.isEmpty()) // new default address
latestAddress = QString::fromStdString(walletModel->getNewAddress("Default").ToString());
ui->labelAddress->setText(latestAddress);
int64_t time = walletModel->getKeyCreationTime(CBitcoinAddress(latestAddress.toStdString()));
ui->labelDate->setText(GUIUtil::dateTimeStr(QDateTime::fromTime_t(static_cast<uint>(time))));
updateQr(latestAddress);
updateLabel();
try {
QString latestAddress = (refreshAddress.isEmpty()) ? this->addressTableModel->getLastUnusedAddress() : refreshAddress;
if (latestAddress.isEmpty()) // new default address
latestAddress = QString::fromStdString(walletModel->getNewAddress("Default").ToString());
ui->labelAddress->setText(latestAddress);
int64_t time = walletModel->getKeyCreationTime(CBitcoinAddress(latestAddress.toStdString()));
ui->labelDate->setText(GUIUtil::dateTimeStr(QDateTime::fromTime_t(static_cast<uint>(time))));
updateQr(latestAddress);
updateLabel();
} catch (const runtime_error& error){
// Error generating address
std::cout << "Error generating address, correct me" << std::endl;
inform("Error generating address");
}
}

void ReceiveWidget::updateLabel(){
Expand Down Expand Up @@ -239,11 +244,17 @@ void ReceiveWidget::onLabelClicked(){
}

void ReceiveWidget::onNewAddressClicked(){
CBitcoinAddress address = walletModel->getNewAddress("");
updateQr(QString::fromStdString(address.ToString()));
ui->labelAddress->setText(!info->address.isEmpty() ? info->address : tr("No address"));
updateLabel();
inform(tr("New address created"));
try {
CBitcoinAddress address = walletModel->getNewAddress("");
updateQr(QString::fromStdString(address.ToString()));
ui->labelAddress->setText(!info->address.isEmpty() ? info->address : tr("No address"));
updateLabel();
inform(tr("New address created"));
} catch (const runtime_error& error){
// Error generating address
std::cout << "Error generating address, correct me" << std::endl;
inform("Error generating address");
}
}

void ReceiveWidget::onCopyClicked(){
Expand Down Expand Up @@ -276,9 +287,7 @@ void ReceiveWidget::onMyAddressesClicked(){

void ReceiveWidget::changeTheme(bool isLightTheme, QString& theme){
// Change theme in all of the childs here..
this->setStyleSheet(theme);
static_cast<AddressHolder*>(this->delegate->getRowFactory())->isLightTheme = isLightTheme;
updateStyle(this);
}

ReceiveWidget::~ReceiveWidget()
Expand Down
4 changes: 0 additions & 4 deletions src/qt/pivx/send.cpp
Expand Up @@ -147,8 +147,6 @@ SendWidget::SendWidget(PIVXGUI* _window, QWidget *parent) :
connect(ui->pushLeft, &QPushButton::clicked, [this](){onPIVSelected(true);});
connect(ui->pushRight, &QPushButton::clicked, [this](){onPIVSelected(false);});
connect(ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(onSendClicked()));

connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(changeTheme(bool, QString&)));
connect(ui->pushButtonAddRecipient, SIGNAL(clicked()), this, SLOT(onAddEntryClicked()));
connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(clearAll()));
}
Expand Down Expand Up @@ -714,14 +712,12 @@ void SendWidget::resizeMenu(){

void SendWidget::changeTheme(bool isLightTheme, QString& theme){
// Change theme in all of the childs here..
this->setStyleSheet(theme);
if(this->menuContacts){
this->menuContacts->setStyleSheet(theme);
if(this->menuContacts->isVisible()){
updateStyle(menuContacts);
}
}
updateStyle(this);
}

SendWidget::~SendWidget()
Expand Down
4 changes: 2 additions & 2 deletions src/qt/pivx/sendmultirow.h
Expand Up @@ -56,8 +56,8 @@ public slots:

protected:
void resizeEvent(QResizeEvent *event) override;
virtual void enterEvent(QEvent *);
virtual void leaveEvent(QEvent *);
virtual void enterEvent(QEvent *) override ;
virtual void leaveEvent(QEvent *) override ;

private slots:
void amountChanged(const QString&);
Expand Down
7 changes: 1 addition & 6 deletions src/qt/pivx/settings/settingswidget.cpp
Expand Up @@ -148,9 +148,6 @@ SettingsWidget::SettingsWidget(PIVXGUI* _window, QWidget *parent) :
connect(ui->pushButtonHelp, SIGNAL(clicked()), this, SLOT(onHelpClicked()));
connect(ui->pushButtonHelp1, SIGNAL(clicked()), this, SLOT(onFaqClicked()));

// Style
connect(window, SIGNAL(themeChanged(bool, QString&)), this, SLOT(changeTheme(bool, QString&)));

// Get restart command-line parameters and handle restart
connect(settingsWalletRepairWidget, &SettingsWalletRepairWidget::handleRestart, [this](QStringList arg){emit handleRestart(arg);});

Expand Down Expand Up @@ -358,9 +355,7 @@ void SettingsWidget::setMapper(){
}

void SettingsWidget::changeTheme(bool isLightTheme, QString& theme){
// Change theme in all of the childs here..
this->setStyleSheet(theme);
updateStyle(this);

}


Expand Down
7 changes: 4 additions & 3 deletions src/qt/pivx/topbar.cpp
Expand Up @@ -137,10 +137,9 @@ TopBar::TopBar(PIVXGUI* _mainWindow, QWidget *parent) :

void TopBar::onThemeClicked(){
// Store theme
bool lightTheme = !ui->pushButtonTheme->isChecked();
bool lightTheme = !isLightTheme();

setTheme(lightTheme);
// TODO: Complete me..
//mainWindow->changeTheme(lightTheme);

if(lightTheme){
ui->pushButtonTheme->setButtonClassStyle("cssClass", "btn-check-theme-light", true);
Expand All @@ -151,6 +150,8 @@ void TopBar::onThemeClicked(){
ui->pushButtonTheme->setButtonText("Dark Theme");
updateStyle(ui->pushButtonTheme);
}

emit changeTheme(lightTheme);
}


Expand Down
2 changes: 2 additions & 0 deletions src/qt/pivx/topbar.h
Expand Up @@ -45,6 +45,8 @@ public slots:
/** Show progress dialog e.g. for verifychain */
void showProgress(const QString& title, int nProgress);

signals:
void changeTheme(bool isLight);
private slots:
void onBtnReceiveClicked();
void onThemeClicked();
Expand Down

0 comments on commit cacce31

Please sign in to comment.