Skip to content

Commit aae1390

Browse files
committed
Fix some bugs and added change color for items in tree
1 parent 49ca920 commit aae1390

8 files changed

+112
-11
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ endif ()
77
#set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/tools/cmake/modules ${CMAKE_MODULE_PATH})
88
set (PROJECT basketpwd)
99
set (LIB_PROJECT basketlib)
10-
set (PROJECT_VERSION 0.4.6)
10+
set (PROJECT_VERSION 0.4.7)
1111
set (HEADERS
1212
aboutdialog.h
1313
src/changepassword.h

basketpwd-gui.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ unix {
7979
mac {
8080
TARGET = "Basket of passwords"
8181
}
82-
VERSION = 0.4.6
82+
VERSION = 0.4.7
8383
VERSTR = '\\"$${VERSION}\\"'
8484
DEFINES += VER=\"$${VERSTR}\"
8585
DEFINES += QMAKE_SET=1

model/basketmodel.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ BasketModel::BasketModel(QObject *parent) :
1313
folderIcon = QIcon(":/images/foldericon");
1414
folderCloseIcon = QIcon(":/images/foldercloseicon");
1515
primarySelectMode = false;
16+
17+
reloadSettings();
1618
}
1719
BasketModel::~BasketModel()
1820
{
@@ -533,7 +535,7 @@ QVariant BasketModel::data(const QModelIndex &index, int role) const
533535
}
534536
else if ( role == Qt::TextColorRole ) {
535537
QBrush blue_brush;
536-
blue_brush.setColor(Qt::darkBlue);
538+
blue_brush.setColor(itemsColor);
537539
if ( !item->isFolder() )
538540
return blue_brush;
539541
}
@@ -795,3 +797,8 @@ void BasketModel::setUnFoldIndex(QModelIndex idx)
795797

796798
emit modelDataChanged();
797799
}
800+
void BasketModel::reloadSettings()
801+
{
802+
QSettings set;
803+
itemsColor = set.value(tr("ItemColor"), QColor(Qt::darkBlue)).value<QColor>();
804+
}

model/basketmodel.h

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Q_OBJECT
6060
QMimeData *mimeData(const QModelIndexList &indexes) const;
6161
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent = QModelIndex());
6262

63+
void reloadSettings();
64+
6365
protected:
6466
#if QT_VERSION < 0x040600
6567
void beginResetModel();
@@ -88,6 +90,8 @@ Q_OBJECT
8890
Qt::SortOrder mainSortOrder;
8991
bool primarySelectMode;
9092

93+
QColor itemsColor;
94+
9195
signals:
9296
void modelDataChanged();
9397
void ThisIndexIsFold(const QModelIndex &index) const;

src/mainwindow.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ MainWindow::MainWindow( QWidget * parent, Qt::WFlags f)
3434
// Добавлено 0.2.6
3535
QSettings set;
3636

37-
defaultPath = set.value(tr("PathToDef"), QString(QDir::currentPath())).toString();
37+
defaultPath = getDefaultDirectory(); //set.value(tr("PathToDef"), QString(QDir::currentPath())).toString();
3838
dontCloseApp = set.value(tr("DontCloseApp"), false).toBool();
3939
sortingEnabled = set.value(tr(SORTING), true).toBool();
4040

@@ -602,6 +602,7 @@ void MainWindow::on_actionSettings_triggered()
602602
model->setIdentifier(sd.getIdent());
603603
setModif(true);
604604
}
605+
model->reloadSettings();
605606
}
606607
}
607608
void MainWindow::on_actionChangeCurrentPassword_triggered()
@@ -679,7 +680,15 @@ void MainWindow::slotChangeStypeApp(QAction *styleAct)
679680
QString MainWindow::getDefaultDirectory() const
680681
{
681682
QSettings set;
682-
QString defaultPath = set.value(tr("PathToDef"), QString(QDir::currentPath())).toString();
683+
684+
#ifdef Q_WS_WIN
685+
QString settingDirName = "Basket of Password";
686+
#else
687+
QString settingDirName = ".basketpwd";
688+
#endif
689+
690+
QString defPath = QString(QDir::homePath() + QDir::separator() + settingDirName);
691+
QString defaultPath = set.value(tr("PathToDef"), QString(defPath)).toString();
683692
return defaultPath;
684693
}
685694

src/settingsdialog.cpp

+36-2
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,35 @@
55
#include "settingsdialog.h"
66
#include "ui_settingsdialog.h"
77

8+
#include <QDebug>
9+
810
SettingsDialog::SettingsDialog(QWidget *parent) :
911
QDialog(parent),
1012
m_ui(new Ui::SettingsDialog)
1113
{
1214
m_ui->setupUi(this);
1315

16+
#ifdef Q_WS_WIN
17+
QString settingDirName = "Basket of Password";
18+
#else
19+
QString settingDirName = ".basketpwd";
20+
#endif
21+
22+
QString defPath = QString(QDir::homePath() + QDir::separator() + settingDirName);
23+
1424
QSettings set;
15-
QString defaultPath = set.value(tr("PathToDef"), QString(QDir::currentPath())).toString();
25+
QString defaultPath = set.value(tr("PathToDef"), QString(defPath)).toString();
1626
int csi = set.value(tr("DontCloseApp"), m_ui->checkBoxDontClose->checkState()).toInt();
1727
int csort_raw = set.value(tr(SORTING), true).toInt();
1828
Qt::CheckState cs = csi == 0 ? Qt::Unchecked : Qt::Checked;
1929
Qt::CheckState csort = csort_raw == 0? Qt::Unchecked : Qt::Checked;
2030
m_ui->checkBoxDontClose->setCheckState(cs);
2131
m_ui->lineEditDefaultPath->setText(defaultPath);
2232
m_ui->checkBoxSort->setCheckState(csort);
33+
34+
/* Colors */
35+
selectedColor = set.value(tr("ItemColor"), QColor(Qt::darkBlue)).value<QColor>();
36+
setColorToItLabel(selectedColor);
2337
}
2438
SettingsDialog::~SettingsDialog()
2539
{
@@ -46,7 +60,7 @@ QString SettingsDialog::getIdent() const
4660
return m_ui->lineEditIdent->text();
4761
}
4862

49-
void SettingsDialog::on_pushButton_clicked()
63+
void SettingsDialog::on_pushButtonSelectDir_clicked()
5064
{
5165
QString oldPath = m_ui->lineEditDefaultPath->text();
5266
QString dir = QFileDialog::getExistingDirectory(this, trUtf8("Выберите папку"),
@@ -79,10 +93,30 @@ void SettingsDialog::on_buttonBox_clicked(QAbstractButton* button)
7993

8094
set.setValue(tr("DontCloseApp"), m_ui->checkBoxDontClose->checkState());
8195
set.setValue(tr(SORTING), m_ui->checkBoxSort->checkState());
96+
set.setValue(tr("ItemColor"), selectedColor);
8297
accept();
8398
}
8499
else if ( m_ui->buttonBox->buttonRole( button ) == QDialogButtonBox::RejectRole )
85100
reject();
86101

87102
}
88103

104+
void SettingsDialog::on_pushButtonSelectColor_clicked()
105+
{
106+
// FIXME: maybe QT bug here O_o
107+
QString tempDir = m_ui->lineEditDefaultPath->text();
108+
QColor sd_color = QColorDialog::getColor( selectedColor, this ); //, tr("Выберите цвет"));
109+
if ( sd_color.isValid() ) {
110+
selectedColor = sd_color;
111+
setColorToItLabel(selectedColor);
112+
}
113+
114+
// FIXME: maybe QT bug here O_o
115+
if ( tempDir != m_ui->lineEditDefaultPath->text() )
116+
m_ui->lineEditDefaultPath->setText(tempDir);
117+
}
118+
void SettingsDialog::setColorToItLabel( QColor &clr )
119+
{
120+
QString ls = tr("<html><head/><body><p><span style=\"color:%1;\">Цвет записей:</span></p></body></html>").arg(clr.name());
121+
m_ui->labelColorItems->setText(ls);
122+
}

src/settingsdialog.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QtGui/QDialog>
55
#include <QAbstractButton>
66
#include <QDateTime>
7+
#include <QColorDialog>
78

89
#define SORTING "SortingEnabled"
910

@@ -25,10 +26,14 @@ class SettingsDialog : public QDialog {
2526

2627
private:
2728
Ui::SettingsDialog *m_ui;
29+
QColor selectedColor;
30+
31+
void setColorToItLabel(QColor &clr);
2832

2933
private slots:
3034
void on_buttonBox_clicked(QAbstractButton* button);
31-
void on_pushButton_clicked();
35+
void on_pushButtonSelectDir_clicked();
36+
void on_pushButtonSelectColor_clicked();
3237
};
3338

3439
#endif // SETTINGSDIALOG_H

ui/settingsdialog.ui

+45-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>480</width>
10-
<height>282</height>
10+
<height>364</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -32,12 +32,12 @@
3232
<item>
3333
<widget class="QLineEdit" name="lineEditDefaultPath">
3434
<property name="text">
35-
<string>./</string>
35+
<string/>
3636
</property>
3737
</widget>
3838
</item>
3939
<item>
40-
<widget class="QPushButton" name="pushButton">
40+
<widget class="QPushButton" name="pushButtonSelectDir">
4141
<property name="minimumSize">
4242
<size>
4343
<width>30</width>
@@ -118,6 +118,48 @@
118118
</layout>
119119
</widget>
120120
</item>
121+
<item>
122+
<widget class="QGroupBox" name="groupBoxVisual">
123+
<property name="title">
124+
<string>Визуальные настройки</string>
125+
</property>
126+
<layout class="QVBoxLayout" name="verticalLayout_4">
127+
<item>
128+
<layout class="QHBoxLayout" name="horizontalLayout_4">
129+
<item>
130+
<widget class="QLabel" name="labelColorItems">
131+
<property name="sizePolicy">
132+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
133+
<horstretch>0</horstretch>
134+
<verstretch>0</verstretch>
135+
</sizepolicy>
136+
</property>
137+
<property name="minimumSize">
138+
<size>
139+
<width>0</width>
140+
<height>0</height>
141+
</size>
142+
</property>
143+
<property name="text">
144+
<string>Цвет записей:</string>
145+
</property>
146+
<property name="textFormat">
147+
<enum>Qt::RichText</enum>
148+
</property>
149+
</widget>
150+
</item>
151+
<item>
152+
<widget class="QPushButton" name="pushButtonSelectColor">
153+
<property name="text">
154+
<string>&amp;Изменить</string>
155+
</property>
156+
</widget>
157+
</item>
158+
</layout>
159+
</item>
160+
</layout>
161+
</widget>
162+
</item>
121163
<item>
122164
<spacer name="verticalSpacer">
123165
<property name="orientation">

0 commit comments

Comments
 (0)