Commit 54e474be authored by Michael Reeves's avatar Michael Reeves

Migrate code from OptionDialog to Options

Begin shifting Option handling to Options class.
parent 246217f9
......@@ -30,7 +30,8 @@ set(kdiff3part_PART_SRCS
Overview.cpp
Logging.cpp
FileNameLineEdit.cpp
MergeEditLine.cpp )
MergeEditLine.cpp
Options.cpp )
add_library(kdiff3part MODULE ${kdiff3part_PART_SRCS})
......
/**
* Copyright (C) 2019 Michael Reeves <reeves.87@gmail.com>
*
* This file is part of KDiff3.
*
* KDiff3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* KDiff3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KDiff3. If not, see <http://www.gnu.org/licenses/>.
*/
#include "options.h"
#include "OptionItems.h"
void Options::init(std::list<OptionItemBase*> &optionItemList)
{
/*
TODO manage toolbar positioning
*/
optionItemList.push_back(new OptionNum<int>( Qt::TopToolBarArea, "ToolBarPos", (int*)&m_toolBarPos));
optionItemList.push_back(new OptionSize(QSize(600, 400), "Geometry", &m_geometry));
optionItemList.push_back(new OptionPoint(QPoint(0, 22), "Position", &m_position));
optionItemList.push_back(new OptionToggleAction(false, "WindowStateMaximised", &m_bMaximised));
optionItemList.push_back(new OptionToggleAction(true, "Show Toolbar", &m_bShowToolBar));
optionItemList.push_back(new OptionToggleAction(true, "Show Statusbar", &m_bShowStatusBar));
}
void Options::apply(const std::list<OptionItemBase*> &optionItemList)
{
std::list<OptionItemBase*>::const_iterator i;
for(i = optionItemList.begin(); i != optionItemList.end(); ++i)
{
(*i)->apply();
}
#ifdef Q_OS_WIN //TODO: Needed? If so move this to optionItemList like everything else.
QString locale = m_options->m_language;
if(locale == "Auto" || locale.isEmpty())
locale = QLocale::system().name().left(2);
int spacePos = locale.indexOf(' ');
if(spacePos > 0) locale = locale.left(spacePos);
QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Software\\KDiff3\\diff-ext"), QSettings::NativeFormat);
settings.setValue(QLatin1String("Language"), locale);
#endif
}
void Options::resetToDefaults(const std::list<OptionItemBase*> &optionItemList)
{
std::list<OptionItemBase*>::const_iterator i;
for(i = optionItemList.begin(); i != optionItemList.end(); ++i)
{
(*i)->setToDefault();
}
}
void Options::setToCurrent(const std::list<OptionItemBase*> &optionItemList)
{
std::list<OptionItemBase*>::const_iterator i;
for(i = optionItemList.begin(); i != optionItemList.end(); ++i)
{
(*i)->setToCurrent();
}
}
......@@ -304,12 +304,12 @@ KDiff3App::KDiff3App(QWidget* pParent, const QString& name, KDiff3Part* pKDiff3P
wordWrap->setChecked(m_pOptions->m_bWordWrap);
if(!isPart())
{
viewStatusBar->setChecked(m_pOptions->m_bShowStatusBar);
viewStatusBar->setChecked(m_pOptions->isStatusBarVisable());
slotViewStatusBar();
KToolBar *mainToolBar = toolBar(MAIN_TOOLBAR_NAME);
if(mainToolBar != nullptr){
mainToolBar->mainWindow()->addToolBar(m_pOptions->m_toolBarPos, mainToolBar);
mainToolBar->mainWindow()->addToolBar(m_pOptions->getToolbarPos(), mainToolBar);
}
// TODO restore window size/pos?
/* QSize size = m_pOptions->m_geometry;
......@@ -357,8 +357,8 @@ void KDiff3App::completeInit(const QString& fn1, const QString& fn2, const QStri
{
if(m_pKDiff3Shell != nullptr)
{
QSize size = m_pOptions->m_geometry;
QPoint pos = m_pOptions->m_position;
QSize size = m_pOptions->getGeometry();
QPoint pos = m_pOptions->getPosition();
if(!size.isEmpty())
{
m_pKDiff3Shell->resize(size);
......@@ -369,7 +369,7 @@ void KDiff3App::completeInit(const QString& fn1, const QString& fn2, const QStri
if(!m_bAutoMode)
{
//Here we want the extra setup showMaximized does since the window has not be shown before
if(m_pOptions->m_bMaximised)
if(m_pOptions->isMaximised())
m_pKDiff3Shell->showMaximized();// krazy:exclude=qmethods
else
m_pKDiff3Shell->show();
......@@ -449,7 +449,7 @@ void KDiff3App::completeInit(const QString& fn1, const QString& fn2, const QStri
if(m_pKDiff3Shell != nullptr)
{
if(m_pOptions->m_bMaximised)
if(m_pOptions->isMaximised())
//We want showMaximized here as the window has never been shown.
m_pKDiff3Shell->showMaximized();// krazy:exclude=qmethods
else
......@@ -651,11 +651,11 @@ void KDiff3App::saveOptions(KSharedConfigPtr config)
{
if(!isPart())
{
m_pOptions->m_bMaximised = m_pKDiff3Shell->isMaximized();
m_pOptions->setMaximised(m_pKDiff3Shell->isMaximized());
if(!m_pKDiff3Shell->isMaximized() && m_pKDiff3Shell->isVisible())
{
m_pOptions->m_geometry = m_pKDiff3Shell->size();
m_pOptions->m_position = m_pKDiff3Shell->pos();
m_pOptions->setGeometry(m_pKDiff3Shell->size());
m_pOptions->setPosition(m_pKDiff3Shell->pos());
}
/* TODO change this option as now KToolbar uses QToolbar positioning style
if ( toolBar(MAIN_TOOLBAR_NAME)!=0 )
......@@ -1026,12 +1026,12 @@ void KDiff3App::slotViewToolBar()
{
Q_ASSERT(viewToolBar != nullptr);
slotStatusMsg(i18n("Toggling toolbar..."));
m_pOptions->m_bShowToolBar = viewToolBar->isChecked();
m_pOptions->setToolbarState(viewToolBar->isChecked());
///////////////////////////////////////////////////////////////////
// turn Toolbar on or off
if(toolBar(MAIN_TOOLBAR_NAME) != nullptr)
{
if(!m_pOptions->m_bShowToolBar)
if(!m_pOptions->isToolBarVisable())
{
toolBar(MAIN_TOOLBAR_NAME)->hide();
}
......@@ -1047,7 +1047,7 @@ void KDiff3App::slotViewToolBar()
void KDiff3App::slotViewStatusBar()
{
slotStatusMsg(i18n("Toggle the statusbar..."));
m_pOptions->m_bShowStatusBar = viewStatusBar->isChecked();
m_pOptions->setStatusBarState(viewStatusBar->isChecked());
///////////////////////////////////////////////////////////////////
//turn Statusbar on or off
if(statusBar() != nullptr)
......
......@@ -496,6 +496,7 @@ OptionDialog::OptionDialog(bool bShowDirMergeSettings, QWidget* parent) : KPageD
//showButtonSeparator( true );
//setHelp( "kdiff3/index.html", QString::null );
m_options->init(m_optionItemList);
setupFontPage();
setupColorPage();
setupEditPage();
......@@ -544,17 +545,6 @@ void OptionDialog::setupOtherOptions()
addOptionItem(new OptionToggleAction(true, "ShowIdenticalFiles", &m_options->m_bDmShowIdenticalFiles));
addOptionItem(new OptionToggleAction(true, "Show Toolbar", &m_options->m_bShowToolBar));
addOptionItem(new OptionToggleAction(true, "Show Statusbar", &m_options->m_bShowStatusBar));
/*
TODO manage toolbar positioning
*/
addOptionItem(new OptionNum<int>( Qt::TopToolBarArea, "ToolBarPos", (int*)&m_options->m_toolBarPos));
addOptionItem(new OptionSize(QSize(600, 400), "Geometry", &m_options->m_geometry));
addOptionItem(new OptionPoint(QPoint(0, 22), "Position", &m_options->m_position));
addOptionItem(new OptionToggleAction(false, "WindowStateMaximised", &m_options->m_bMaximised));
addOptionItem(new OptionStringList(&m_options->m_recentAFiles, "RecentAFiles"));
addOptionItem(new OptionStringList(&m_options->m_recentBFiles, "RecentBFiles"));
addOptionItem(new OptionStringList(&m_options->m_recentCFiles, "RecentCFiles"));
......@@ -1571,23 +1561,9 @@ void OptionDialog::slotOk()
/** Copy the values from the widgets to the public variables.*/
void OptionDialog::slotApply()
{
std::list<OptionItemBase*>::iterator i;
for(i = m_optionItemList.begin(); i != m_optionItemList.end(); ++i)
{
(*i)->apply();
}
m_options->apply(m_optionItemList);
emit applyDone();
#ifdef Q_OS_WIN
QString locale = m_options->m_language;
if(locale == "Auto" || locale.isEmpty())
locale = QLocale::system().name().left(2);
int spacePos = locale.indexOf(' ');
if(spacePos > 0) locale = locale.left(spacePos);
QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Software\\KDiff3\\diff-ext"), QSettings::NativeFormat);
settings.setValue(QLatin1String("Language"), locale);
#endif
}
/** Set the default values in the widgets only, while the
......@@ -1603,23 +1579,14 @@ void OptionDialog::slotDefault()
void OptionDialog::resetToDefaults()
{
std::list<OptionItemBase*>::iterator i;
for(i = m_optionItemList.begin(); i != m_optionItemList.end(); ++i)
{
(*i)->setToDefault();
}
m_options->resetToDefaults(m_optionItemList);
slotEncodingChanged();
}
/** Initialise the widgets using the values in the public varibles. */
void OptionDialog::setState()
{
std::list<OptionItemBase*>::iterator i;
for(i = m_optionItemList.begin(); i != m_optionItemList.end(); ++i)
{
(*i)->setToCurrent();
}
m_options->setToCurrent(m_optionItemList);
slotEncodingChanged();
}
......
......@@ -29,6 +29,8 @@
#include <QColor>
#include <list>
class OptionItemBase;
enum e_LineEndStyle
{
eLineEndStyleUnix=0,
......@@ -41,6 +43,33 @@ enum e_LineEndStyle
class Options
{
public:
void init(std::list<OptionItemBase*> &optionItemList);
void apply(const std::list<OptionItemBase*> &optionItemList);
void resetToDefaults(const std::list<OptionItemBase*> &optionItemList);
void setToCurrent(const std::list<OptionItemBase*>& optionItemList);
const QSize& getGeometry() const { return m_geometry; }
void setGeometry(const QSize& size) { m_geometry = size; }
const QPoint& getPosition() const { return m_position; }
void setPosition(const QPoint& pos) { m_position = pos; }
bool isMaximised() const { return m_bMaximised; };
void setMaximised(const bool maximised) { m_bMaximised = maximised;};
Qt::ToolBarArea getToolbarPos() const { return m_toolBarPos; }
bool isToolBarVisable() const { return m_bShowToolBar; }
void setToolbarState(bool inShown) { m_bShowToolBar = inShown; }
bool isStatusBarVisable() const { return m_bShowStatusBar; }
void setStatusBarState(bool inShown) { m_bShowStatusBar = inShown; }
private:
// Some settings are not available in the option dialog:
QSize m_geometry = QSize(600, 400);
QPoint m_position = QPoint(0, 22);
......@@ -48,6 +77,7 @@ public:
bool m_bShowToolBar = true;
bool m_bShowStatusBar = true;
Qt::ToolBarArea m_toolBarPos = Qt::TopToolBarArea;
public:
// These are the results of the option dialog.
QFont m_font;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment