src/configDialog.h

Tue, 07 Jul 2015 21:35:20 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 07 Jul 2015 21:35:20 +0300
changeset 941
f895379d7fab
parent 927
409b82a4765e
permissions
-rw-r--r--

Refactoring update.
Removed all asserts.

/*
 *  LDForge: LDraw parts authoring CAD
 *  Copyright (C) 2013 - 2015 Teemu Piippo
 *
 *  This program 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include "mainWindow.h"
#include <QDialog>

// =============================================================================
class ConfigDialog : public QDialog
{
	Q_OBJECT

public:
	enum Tab
	{
		InterfaceTab,
		EditingToolsTab,
		ProfileTab,
		ShortcutsTab,
		QuickColorsTab,
		GridsTab,
		ExtProgsTab,
		DownloadTab
	};

	struct ShortcutInfo
	{
		QAction* action;
		QKeySequence sequence;
	};

	using ShortcutInfoMap = QMap<QListWidgetItem*, ShortcutInfo>;

	ConfigDialog (QWidget* parent = nullptr, Qt::WindowFlags f = 0);
	ConfigDialog (Tab deftab, QWidget* parent = nullptr, Qt::WindowFlags f = 0);
	virtual ~ConfigDialog();

private:
	class Ui_ConfigUI& ui;
	QList<QListWidgetItem*> m_colorToolbarItems;
	QList<ColorToolbarEntry> m_colorToolbarEntries;
	QMap<QPushButton*, QColor> m_buttonColors;
	ShortcutInfoMap m_shortcutInfo;
	bool m_hasValidMainWindow;

	void applySettings();
	void addShortcut (QAction* act);
	void setButtonBackground (QPushButton* button, QString value);
	void updateQuickColorList (ColorToolbarEntry* selected = nullptr);
	void setShortcutText (QListWidgetItem* item);
	int getItemRow (QListWidgetItem* item, QList<QListWidgetItem*>& haystack);
	QString quickColorString();
	QListWidgetItem* getSelectedQuickColor();
	QList<QListWidgetItem*> getShortcutSelection();
	void initExtProgs();
	void applyToWidgetOptions (std::function<void (QWidget*, AbstractConfigEntry*)> func);

signals:
	void settingsApplied();

private slots:
	void setButtonColor();
	void slot_setShortcut();
	void slot_resetShortcut();
	void slot_clearShortcut();
	void slot_setColor();
	void slot_delColor();
	void slot_addColorSeparator();
	void slot_moveColor();
	void slot_clearColors();
	void slot_setExtProgPath();
	void slot_findDownloadFolder();
	void buttonClicked (QAbstractButton* button);
	void selectPage (int row);
};

// =============================================================================
//
class KeySequenceDialog : public QDialog
{
	Q_OBJECT

public:
	explicit KeySequenceDialog (QKeySequence keySequence, QWidget* parent = nullptr, Qt::WindowFlags f = 0);
	QKeySequence keySequence() const;

private:
	void updateOutput();

	class QLabel* m_outputLabel;
	QDialogButtonBox* m_buttonBox;
	QKeySequence m_keySequence;

private slots:
	virtual void keyPressEvent (QKeyEvent* ev) override;
};

mercurial