Page MenuHomePhabricator (Chris)

No OneTemporary

Size
11 KB
Referenced Files
None
Subscribers
None
diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp
index e945729..3204c4d 100644
--- a/src/SettingsDialog.cpp
+++ b/src/SettingsDialog.cpp
@@ -1,225 +1,227 @@
#include "SettingsDialog.h"
#include "ui_SettingsDialog.h"
#include "MySettings.h"
#include "common/misc.h"
#include <QFileDialog>
static int page_number = 0;
SettingsDialog::SettingsDialog(MainWindow *parent) :
QDialog(parent),
ui(new Ui::SettingsDialog)
{
ui->setupUi(this);
Qt::WindowFlags flags = windowFlags();
flags &= ~Qt::WindowContextHelpButtonHint;
setWindowFlags(flags);
mainwindow_ = parent;
loadSettings();
QTreeWidgetItem *item;
auto AddPage = [&](QWidget *page){
page->layout()->setMargin(0);
QString name = page->windowTitle();
item = new QTreeWidgetItem();
item->setText(0, name);
item->setData(0, Qt::UserRole, QVariant::fromValue((uintptr_t)(QWidget *)page));
ui->treeWidget->addTopLevelItem(item);
};
AddPage(ui->page_general);
AddPage(ui->page_programs);
AddPage(ui->page_behavior);
AddPage(ui->page_network);
AddPage(ui->page_visual);
// AddPage(ui->page_example);
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(page_number));
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
namespace {
template <typename T> class GetValue {
private:
public:
MySettings &settings;
QString name;
GetValue(MySettings &s, QString const &name)
: settings(s)
, name(name)
{
}
// void operator >> (T &value)
// {
// value = settings.value(name, value).template value<T>();
// }
};
template <typename T> void operator >> (GetValue<T> const &l, T &r)
{
r = l.settings.value(l.name, r).template value<T>();
}
template <> void operator >> (GetValue<QColor> const &l, QColor &r)
{
- r = l.settings.value(l.name, r).template value<QString>(); // 文字列で取得
-
+ QString s = l.settings.value(l.name, QString()).template value<QString>(); // 文字列で取得
+ if (s.startsWith('#')) {
+ r = s;
+ }
}
template <typename T> class SetValue {
private:
public:
MySettings &settings;
QString name;
SetValue(MySettings &s, QString const &name)
: settings(s)
, name(name)
{
}
// void operator << (T const &value)
// {
// settings.setValue(name, value);
// }
};
template <typename T> void operator << (SetValue<T> const &l, T const &r) // 左辺をconstにしないとビルドが通らない
{
const_cast<SetValue<T> *>(&l)->settings.setValue(l.name, r);
}
template <> void operator << (SetValue<QColor> const &l, QColor const &r)
{
QString s = QString::asprintf("#%02x%02x%02x", r.red(), r.green(), r.blue());
const_cast<SetValue<QColor> *>(&l)->settings.setValue(l.name, s);
}
} // namespace
void SettingsDialog::loadSettings(ApplicationSettings *as)
{
MySettings s;
*as = ApplicationSettings::defaultSettings();
s.beginGroup("Global");
GetValue<bool>(s, "SaveWindowPosition") >> as->remember_and_restore_window_position;
GetValue<QString>(s, "DefaultWorkingDirectory") >> as->default_working_dir;
GetValue<QString>(s, "GitCommand") >> as->git_command;
GetValue<QString>(s, "FileCommand") >> as->file_command;
GetValue<QString>(s, "GpgCommand") >> as->gpg_command;
GetValue<QString>(s, "SshCommand") >> as->ssh_command;
s.endGroup();
s.beginGroup("UI");
GetValue<bool>(s, "EnableHighDpiScaling") >> as->enable_high_dpi_scaling;
GetValue<bool>(s, "ShowLabels") >> as->show_labels;
s.endGroup();
s.beginGroup("Network");
GetValue<QString>(s, "ProxyType") >> as->proxy_type;
GetValue<QString>(s, "ProxyServer") >> as->proxy_server;
GetValue<bool>(s, "GetCommitterIcon") >> as->get_committer_icon;
s.endGroup();
as->proxy_server = misc::makeProxyServerURL(as->proxy_server);
s.beginGroup("Behavior");
GetValue<bool>(s, "AutomaticFetch") >> as->automatically_fetch_when_opening_the_repository;
GetValue<unsigned int>(s, "MaxCommitItemAcquisitions") >> as->maximum_number_of_commit_item_acquisitions;
s.endGroup();
s.beginGroup("Visual");
GetValue<QColor>(s, "LabelColorHead") >> as->branch_label_color.head;
GetValue<QColor>(s, "LabelColorLocalBranch") >> as->branch_label_color.local;
GetValue<QColor>(s, "LabelColorRemoteBranch") >> as->branch_label_color.remote;
GetValue<QColor>(s, "LabelColorTag") >> as->branch_label_color.tag;
s.endGroup();
}
void SettingsDialog::saveSettings(ApplicationSettings const *as)
{
MySettings s;
s.beginGroup("Global");
SetValue<bool>(s, "SaveWindowPosition") << as->remember_and_restore_window_position;
SetValue<QString>(s, "DefaultWorkingDirectory") << as->default_working_dir;
SetValue<QString>(s, "GitCommand") << as->git_command;
SetValue<QString>(s, "FileCommand") << as->file_command;
SetValue<QString>(s, "GpgCommand") << as->gpg_command;
SetValue<QString>(s, "SshCommand") << as->ssh_command;
s.endGroup();
s.beginGroup("UI");
SetValue<bool>(s, "EnableHighDpiScaling") << as->enable_high_dpi_scaling;
SetValue<bool>(s, "ShowLabels") << as->show_labels;
s.endGroup();
s.beginGroup("Network");
SetValue<QString>(s, "ProxyType") << as->proxy_type;
SetValue<QString>(s, "ProxyServer") << misc::makeProxyServerURL(as->proxy_server);
SetValue<bool>(s, "GetCommitterIcon") << as->get_committer_icon;
s.endGroup();
s.beginGroup("Behavior");
SetValue<bool>(s, "AutomaticFetch") << as->automatically_fetch_when_opening_the_repository;
SetValue<unsigned int>(s, "MaxCommitItemAcquisitions") << as->maximum_number_of_commit_item_acquisitions;
s.endGroup();
s.beginGroup("Visual");
SetValue<QColor>(s, "LabelColorHead") << as->branch_label_color.head;
SetValue<QColor>(s, "LabelColorLocalBranch") << as->branch_label_color.local;
SetValue<QColor>(s, "LabelColorRemoteBranch") << as->branch_label_color.remote;
SetValue<QColor>(s, "LabelColorTag") << as->branch_label_color.tag;
s.endGroup();
}
void SettingsDialog::saveSettings()
{
saveSettings(&set);
}
void SettingsDialog::exchange(bool save)
{
QList<AbstractSettingForm *> forms = ui->stackedWidget->findChildren<AbstractSettingForm *>();
for (AbstractSettingForm *form : forms) {
form->exchange(save);
}
}
void SettingsDialog::loadSettings()
{
loadSettings(&set);
exchange(false);
}
void SettingsDialog::done(int r)
{
page_number = ui->treeWidget->currentIndex().row();
QDialog::done(r);
}
void SettingsDialog::accept()
{
exchange(true);
saveSettings();
done(QDialog::Accepted);
}
void SettingsDialog::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
(void)previous;
if (current) {
uintptr_t p = current->data(0, Qt::UserRole).value<uintptr_t>();
QWidget *w = reinterpret_cast<QWidget *>(p);
Q_ASSERT(w);
ui->stackedWidget->setCurrentWidget(w);
}
}
diff --git a/src/coloredit/RingSlider.cpp b/src/coloredit/RingSlider.cpp
index 69f0fca..035462e 100644
--- a/src/coloredit/RingSlider.cpp
+++ b/src/coloredit/RingSlider.cpp
@@ -1,189 +1,190 @@
#include "RingSlider.h"
//#include "misc.h"
#include <QKeyEvent>
#include <QPainter>
+#include <QPainterPath>
#include <math.h>
void RingSlider::updateGeometry()
{
handle_size_ = height();
int x = handle_size_ / 2;
int w = width() - handle_size_;
slider_rect_ = QRect(x, 3, w, height() - 6);
int val = value();
int max = maximum();
int handle_x = val * slider_rect_.width() / (max + 1) + slider_rect_.x() - handle_size_ / 2;
handle_rect_ = QRect(handle_x, 0, handle_size_, handle_size_);
slider_image_cache_ = QImage();
}
QSize RingSlider::sliderImageSize() const
{
return slider_rect_.size();
}
void RingSlider::offset(int delta)
{
setValue(value() + delta);
}
void RingSlider::resizeEvent(QResizeEvent *e)
{
QWidget::resizeEvent(e);
updateGeometry();
}
void RingSlider::keyPressEvent(QKeyEvent *e)
{
int k = e->key();
switch (k) {
case Qt::Key_Home:
setValue(minimum());
return;
case Qt::Key_End:
setValue(maximum());
return;
case Qt::Key_Left:
offset(-singleStep());
return;
case Qt::Key_Right:
offset(singleStep());
return;
case Qt::Key_PageDown:
offset(-pageStep());
return;
case Qt::Key_PageUp:
offset(pageStep());
return;
}
}
void RingSlider::paintEvent(QPaintEvent *)
{
updateGeometry();
slider_image_cache_ = generateSliderImage();
QPainter pr(this);
pr.setRenderHint(QPainter::Antialiasing);
{ // left rounded cap
int h = slider_rect_.height();
QRect r(slider_rect_.x() - h / 2 - 1, slider_rect_.y(), h, h);
QRectF fr(r);
QPainterPath path;
path.addEllipse(fr);
pr.save();
pr.setClipPath(path);
pr.fillRect(fr, Qt::black);
fr.adjust(1, 1, -1, -1);
QPainterPath path2;
path2.addEllipse(fr);
pr.setClipPath(path2);
pr.drawImage(fr, slider_image_cache_, QRect(0, 0, 1, slider_image_cache_.height()));
pr.restore();
}
{ // right rounded cap
int h = slider_rect_.height();
QRect r(slider_rect_.x() + slider_rect_.width() - h / 2, slider_rect_.y(), h, h);
QRectF fr(r);
QPainterPath path;
path.addEllipse(fr);
pr.save();
pr.setClipPath(path);
pr.fillRect(fr, Qt::black);
fr.adjust(1, 1, -1, -1);
QPainterPath path2;
path2.addEllipse(fr);
pr.setClipPath(path2);
pr.drawImage(fr, slider_image_cache_, QRect(slider_image_cache_.width() - 1, 0, 1, slider_image_cache_.height()));
pr.restore();
}
{ // top and bottom border
int x = slider_rect_.x();
int y = slider_rect_.y();
int w = slider_rect_.width();
int h = slider_rect_.height();
pr.fillRect(x, y, w, 1, Qt::black);
pr.fillRect(x, y + h - 1, w, 1, Qt::black);
}
pr.drawImage(slider_rect_.adjusted(0, 1, 0, -1), slider_image_cache_, slider_image_cache_.rect());
// slider handle
{
QPainterPath path;
path.addRect(rect());
QPainterPath path2;
path2.addEllipse(handle_rect_.adjusted(4, 4, -4, -4));
path = path.subtracted(path2);
pr.setClipPath(path);
pr.setPen(Qt::NoPen);
pr.setBrush(Qt::black);
pr.drawEllipse(handle_rect_);
pr.setBrush(Qt::white);
pr.drawEllipse(handle_rect_.adjusted(1, 1, -1, -1));
pr.setPen(Qt::NoPen);
pr.setBrush(Qt::black);
pr.drawEllipse(handle_rect_.adjusted(3, 3, -3, -3));
}
}
void RingSlider::mousePressEvent(QMouseEvent *e)
{
int x = e->pos().x();
if (x < handle_rect_.x()) {
offset(-pageStep());
return;
}
if (x >= handle_rect_.x() + handle_rect_.width()) {
offset(pageStep());
return;
}
mouse_press_value_ = value();
mouse_press_pos_ = e->pos();
}
void RingSlider::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton) {
double slider_w = slider_rect_.width();
double range = maximum() - minimum();
double x = (mouse_press_value_ - minimum()) * slider_w / range + e->pos().x() - mouse_press_pos_.x();
int v = int(x * range / slider_w + minimum());
setValue(v);
return;
}
}
void RingSlider::mouseDoubleClickEvent(QMouseEvent *e)
{
int w = slider_rect_.width();
if (w > 1) {
double x = (e->pos().x() - slider_rect_.x()) * (maximum() - minimum()) / (w - 1);
int v = floor(x + 0.5);
v = std::clamp(v, minimum(), maximum());
setValue(v);
}
}
void RingSlider::wheelEvent(QWheelEvent *e)
{
int delta = e->delta();
bool sign = (delta < 0);
if (sign) delta = -delta;
delta = (delta + 119) / 120;
if (sign) delta = -delta;
offset(delta);
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Feb 7, 8:50 AM (21 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55927
Default Alt Text
(11 KB)

Event Timeline