Browse Source

[REFACTORING] d-pointer + 1 file per class

master
Ulrich Van Den Hekke 11 years ago
parent
commit
12f115342a
  1. 37
      components/borderlayout.cpp
  2. 19
      components/borderlayout.h
  3. 76
      components/borderlayout_p.h
  4. 79
      components/completerdirmodel.cpp
  5. 41
      components/completerdirmodel.h
  6. 286
      components/customschemeimpl.cpp
  7. 27
      components/customschemeimpl.h
  8. 63
      components/customschemeimpl_p.h
  9. 393
      components/directoryedit.cpp
  10. 50
      components/directoryedit.h
  11. 42
      components/directoryedit_p.h
  12. 157
      components/directoryeditwidget.cpp
  13. 60
      components/directoryeditwidget.h
  14. 41
      components/directoryeditwidget_p.h
  15. 2
      framework/application/customdialog/customgeneralimpl.cpp
  16. 2
      framework/application/customdialog/customprojectimpl.cpp
  17. 2
      framework/application/customdialog/directoryeditdelegate.cpp
  18. 2
      framework/application/customdialog/ui/customgeneral.ui
  19. 2
      framework/application/customdialog/ui/customproject.ui
  20. 2
      framework/application/newversion.ui
  21. 2
      framework/application/newversionwizardimpl.cpp
  22. 4
      framework/application/xinxprojectwizard/projectwizard.cpp
  23. 2
      framework/editors/newfilewizard.ui
  24. 1
      framework/editors/newfilewizardimpl.cpp
  25. 2
      framework/search/replace.ui
  26. 1
      framework/search/replacedialogimpl.cpp
  27. 2
      plugins/core/pluginproperty/parserprojectproperty.ui
  28. 1
      plugins/core/pluginproperty/parserprojectpropertyimpl.cpp
  29. 1
      plugins/generix/projectproperty/std/generixderivationpage.cpp
  30. 2
      plugins/generix/projectproperty/wizard/newgenerixinformationpage.ui
  31. 1
      plugins/generix/projectproperty/wizard/newgenerixinformationpageimpl.cpp
  32. 2
      plugins/generix/savedialog/derivationdialog.ui
  33. 1
      plugins/generix/savedialog/derivationdialogimpl.cpp
  34. 3
      xinxcrash/tracticketcreationwizard.cpp
  35. 2
      xinxcrash/tracticketcreationwizard.ui

37
components/borderlayout.cpp

@ -45,7 +45,7 @@
#include <QWidgetItem>
// Components header
#include "borderlayout.h"
#include "borderlayout_p.h"
/*!
* \defgroup Components Visual Components used by XINX
@ -101,8 +101,7 @@
* \param margin The marge arround the layout
* \param spacing The space between widgets
*/
BorderLayout::BorderLayout(QWidget *parent, int margin, int spacing) :
QLayout(parent)
BorderLayout::BorderLayout(QWidget *parent, int margin, int spacing) : QLayout(parent), d(new BorderLayoutPrivate)
{
setMargin(margin);
setSpacing(spacing);
@ -149,7 +148,7 @@ void BorderLayout::addWidget(QWidget *widget, Position position)
*/
void BorderLayout::add(QLayoutItem *item, Position position)
{
list.append(new ItemWrapper(item, position));
d->list.append(new BorderLayoutPrivate::ItemWrapper(item, position));
}
/*!
@ -172,13 +171,13 @@ bool BorderLayout::hasHeightForWidth() const
//! Number of layout added in the BorderLayout
int BorderLayout::count() const
{
return list.size();
return d->list.size();
}
//! Return the \p index item of the list.
QLayoutItem *BorderLayout::itemAt(int index) const
{
ItemWrapper *wrapper = list.value(index);
BorderLayoutPrivate::ItemWrapper *wrapper = d->list.value(index);
if (wrapper)
return wrapper->item;
else
@ -193,13 +192,13 @@ QLayoutItem *BorderLayout::itemAt(int index) const
*/
QSize BorderLayout::minimumSize() const
{
return calculateSize(MinimumSize);
return d->calculateSize(BorderLayoutPrivate::MinimumSize);
}
//! Set this item's geometry to r.
void BorderLayout::setGeometry(const QRect &rect)
{
ItemWrapper *center = 0;
BorderLayoutPrivate::ItemWrapper *center = 0;
int eastWidth = 0;
int westWidth = 0;
int northHeight = 0;
@ -209,9 +208,9 @@ void BorderLayout::setGeometry(const QRect &rect)
QLayout::setGeometry(rect);
for (i = 0; i < list.size(); ++i)
for (i = 0; i < d->list.size(); ++i)
{
ItemWrapper *wrapper = list.at(i);
BorderLayoutPrivate::ItemWrapper *wrapper = d->list.at(i);
QLayoutItem *item = wrapper->item;
Position position = wrapper->position;
@ -239,9 +238,9 @@ void BorderLayout::setGeometry(const QRect &rect)
centerHeight = rect.height() - northHeight - southHeight;
for (i = 0; i < list.size(); ++i)
for (i = 0; i < d->list.size(); ++i)
{
ItemWrapper *wrapper = list.at(i);
BorderLayoutPrivate::ItemWrapper *wrapper = d->list.at(i);
QLayoutItem *item = wrapper->item;
Position position = wrapper->position;
@ -275,28 +274,28 @@ void BorderLayout::setGeometry(const QRect &rect)
*/
QSize BorderLayout::sizeHint() const
{
return calculateSize(SizeHint);
return d->calculateSize(BorderLayoutPrivate::SizeHint);
}
//! Returns the item at the index \p index in the list and removes it.
QLayoutItem *BorderLayout::takeAt(int index)
{
if (index >= 0 && index < list.size())
if (index >= 0 && index < d->list.size())
{
ItemWrapper *layoutStruct = list.takeAt(index);
BorderLayoutPrivate::ItemWrapper *layoutStruct = d->list.takeAt(index);
return layoutStruct->item;
}
return 0;
}
QSize BorderLayout::calculateSize(SizeType sizeType) const
QSize BorderLayoutPrivate::calculateSize(SizeType sizeType) const
{
QSize totalSize;
for (int i = 0; i < list.size(); ++i)
{
ItemWrapper *wrapper = list.at(i);
Position position = wrapper->position;
BorderLayout::Position position = wrapper->position;
QSize itemSize;
if (wrapper->item->isEmpty()) continue;
@ -307,10 +306,10 @@ QSize BorderLayout::calculateSize(SizeType sizeType) const
// (sizeType == SizeHint)
itemSize = wrapper->item->sizeHint();
if (position == North || position == South || position == Center)
if (position == BorderLayout::North || position == BorderLayout::South || position == BorderLayout::Center)
totalSize.rheight() += itemSize.height();
if (position == West || position == East || position == Center)
if (position == BorderLayout::West || position == BorderLayout::East || position == BorderLayout::Center)
totalSize.rwidth() += itemSize.width();
}
return totalSize;

19
components/borderlayout.h

@ -50,6 +50,8 @@
#include <components-config.h>
class BorderLayoutPrivate;
class COMPONENTSEXPORT BorderLayout : public QLayout
{
Q_OBJECT
@ -72,22 +74,7 @@ public:
virtual QSize sizeHint() const;
virtual QLayoutItem *takeAt(int index);
private:
struct ItemWrapper
{
ItemWrapper(QLayoutItem *i, Position p)
{
item = i;
position = p;
}
QLayoutItem *item;
Position position;
};
enum SizeType { MinimumSize, SizeHint };
QSize calculateSize(SizeType sizeType) const;
QList<ItemWrapper *> list;
QScopedPointer<BorderLayoutPrivate> d;
};
#endif

76
components/borderlayout_p.h

@ -0,0 +1,76 @@
/****************************************************************************
**
** Copyright (C) 2004-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the example classes of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Alternatively you may (at
** your option) use any later version of the GNU General Public
** License if such license has been publicly approved by Trolltech ASA
** (or its successors, if any) and the KDE Free Qt Foundation. In
** addition, as a special exception, Trolltech gives you certain
** additional rights. These rights are described in the Trolltech GPL
** Exception version 1.2, which can be found at
** http://www.trolltech.com/products/qt/gplexception/ and in the file
** GPL_EXCEPTION.txt in this package.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
** you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** In addition, as a special exception, Trolltech, as the sole
** copyright holder for Qt Designer, grants users of the Qt/Eclipse
** Integration plug-in the right for the Qt/Eclipse Integration to
** link to functionality provided by Qt Designer and its related
** libraries.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
** granted herein.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#pragma once
#ifndef BORDERLAYOUT_P_H
#define BORDERLAYOUT_P_H
// Xinx header
#include "borderlayout.h"
// Qt header
#include <QLayoutItem>
#include <QList>
class BorderLayoutPrivate
{
public:
struct ItemWrapper
{
ItemWrapper(QLayoutItem *i, BorderLayout::Position p)
{
item = i;
position = p;
}
QLayoutItem *item;
BorderLayout::Position position;
};
enum SizeType { MinimumSize, SizeHint };
QSize calculateSize(SizeType sizeType) const;
QList<ItemWrapper *> list;
};
#endif /* BORDERLAYOUT_P_H */

79
components/completerdirmodel.cpp

@ -0,0 +1,79 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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/>.
*/
// Xinx header
#include "completerdirmodel.h"
// Qt header
#include <QDir>
/* CompleterDirModel */
/*!
* \ingroup Components
* \class CompleterDirModel
* \since 0.7.0.0
*
* \brief Class used by DirectoryEdit to complete on path.
*
* Completer model class based on a QDirModel which permit to propose a completion on
* the path.
* The CompleterDirModel convert path on native separtor. If the path end with a separator,
* the separator is deleted.
*
* To use this modele, we can use a QCompleter on a QLineEdit.
*
* \code
* QLineEdit * lineEdit = new QLineEdit;
*
* QCompleter * completer = new QCompleter(lineEdit);
* lineEdit->setCompleter(completer);
*
* CompleterDirModel * model = new CompleterDirModel(completer);
* completer->setModel(model);
* \endcode
*/
/*!
* \brief Construct a CompleterDirModel.
* \param parent The parent of the object.
*/
CompleterDirModel::CompleterDirModel(QObject *parent) : QDirModel(parent)
{
}
/*!
* \brief Return the data to change in the completion dir model.
*
* This model show the good separator (with the \p QDir::toNativeSepartors() function).
* \param index The model index, represents a path in the tree.
* \param role Only the role Qt::DisplayRole is modified in this object.
*/
QVariant CompleterDirModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole && index.column() == 0)
{
QString path = QDir::toNativeSeparators(filePath(index));
if (path.endsWith(QDir::separator()))
path.chop(1);
return path;
}
return QDirModel::data(index, role);
}

41
components/completerdirmodel.h

@ -0,0 +1,41 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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
#ifndef __COMPLETERDIRMODEL_H__
#define __COMPLETERDIRMODEL_H__
// Qt header
#include <QDirModel>
#include <components-config.h>
class COMPONENTSEXPORT CompleterDirModel : public QDirModel
{
Q_OBJECT
Q_CLASSINFO("Author", "Ulrich Van Den Hekke")
Q_CLASSINFO("URL", "http://xinx.shadoware.org")
Q_CLASSINFO("Licence", "GPL v2 or later")
public:
CompleterDirModel(QObject *parent = 0);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
};
#endif // __COMPLETERDIRMODEL_H__

286
components/customschemeimpl.cpp

@ -18,7 +18,7 @@
*/
// Xinx header
#include "customschemeimpl.h"
#include "customschemeimpl_p.h"
// QCodeEdit header
#include <qcodeedit.h>
@ -32,6 +32,128 @@
// Qt header
#include <QHBoxLayout>
/* CustomSchemeImplPrivate */
CustomSchemeImplPrivate::CustomSchemeImplPrivate() : _ui(new Ui::CustomScheme), m_languageFactory(0), m_formats(0), m_currentFormat(0), m_currentItem(0)
{
}
CustomSchemeImplPrivate::~CustomSchemeImplPrivate()
{
}
void CustomSchemeImplPrivate::on_m_formatsListView_currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)
{
if (current != m_currentItem)
{
m_currentItem = current;
if (m_currentItem && m_formats)
{
m_currentFormat = &(m_formats->formatRef(m_currentItem->text()));
_ui->m_boldCheckBox->setChecked(m_currentFormat->weight != QFont::Normal);
_ui->m_overLineCheckBox->setChecked(m_currentFormat->overline);
_ui->m_strikeOutCheckBox->setChecked(m_currentFormat->strikeout);
_ui->m_italicCheckBox->setChecked(m_currentFormat->italic);
_ui->m_underLineCheckBox->setChecked(m_currentFormat->underline || m_currentFormat->waveUnderline);
_ui->m_waveUnderLineCheckBox->setChecked(m_currentFormat->waveUnderline);
_ui->m_foreGroundComboBox->setColor(m_currentFormat->foreground);
_ui->m_backGroundComboBox->setColor(m_currentFormat->background);
}
_ui->m_formatGroupBox->setEnabled(m_currentItem);
_ui->m_colorGroupBox->setEnabled(m_currentItem);
_ui->m_exampleGroupBox->setEnabled(m_currentItem);
}
}
void CustomSchemeImplPrivate::on_m_boldCheckBox_stateChanged(int state)
{
if (state == Qt::Checked)
m_currentFormat->weight = QFont::Bold;
else
m_currentFormat->weight = QFont::Normal;
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImplPrivate::on_m_overLineCheckBox_stateChanged(int state)
{
m_currentFormat->overline = state == Qt::Checked;
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImplPrivate::on_m_strikeOutCheckBox_stateChanged(int state)
{
m_currentFormat->strikeout = state == Qt::Checked;
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImplPrivate::on_m_italicCheckBox_stateChanged(int state)
{
m_currentFormat->italic = state == Qt::Checked;
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImplPrivate::on_m_underLineCheckBox_stateChanged(int state)
{
m_currentFormat->underline = (state == Qt::Checked) && (_ui->m_waveUnderLineCheckBox->isChecked() == Qt::Unchecked);
m_currentFormat->waveUnderline = (state == Qt::Checked) && (_ui->m_waveUnderLineCheckBox->isChecked() == Qt::Checked);
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImplPrivate::on_m_waveUnderLineCheckBox_stateChanged(int state)
{
m_currentFormat->underline = _ui->m_underLineCheckBox->isChecked() && (state == Qt::Unchecked);
m_currentFormat->waveUnderline = _ui->m_underLineCheckBox->isChecked() && (state == Qt::Checked);
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImplPrivate::on_m_foreGroundComboBox_activated(const QColor &col)
{
m_currentFormat->foreground = col;
if (m_currentFormat->background.isValid()) m_currentItem->setBackground(m_currentFormat->background);
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImplPrivate::on_m_backGroundComboBox_activated(const QColor &col)
{
m_currentFormat->background = col;
if (m_currentFormat->foreground.isValid()) m_currentItem->setForeground(m_currentFormat->foreground);
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImplPrivate::updateFormatList()
{
_ui->m_formatsListView->clear();
if (m_formats)
{
foreach(const QString & f, m_formats->formats())
{
QFormat format = m_formats->format(f);
QListWidgetItem * item = new QListWidgetItem(f, _ui->m_formatsListView);
if (format.background.isValid()) item->setBackground(format.background);
if (format.foreground.isValid()) item->setForeground(format.foreground);
item->setFont(format.toTextCharFormat().font());
item->setHidden(m_hiddenFormat.contains(f));
}
}
if (_ui->m_formatsListView->count())
_ui->m_formatsListView->setCurrentRow(0);
}
/* CustomSchemeImpl */
/*!
* \ingroup Components
* \class CustomSchemeImpl
@ -60,15 +182,15 @@
* \param parent The parent widget
* \param f Flags for the widget
*/
CustomSchemeImpl::CustomSchemeImpl(QWidget * parent, Qt::WindowFlags f) : QWidget(parent, f), m_languageFactory(0), m_formats(0), m_currentFormat(0), m_currentItem(0)
CustomSchemeImpl::CustomSchemeImpl(QWidget * parent, Qt::WindowFlags f) : QWidget(parent, f), d(new CustomSchemeImplPrivate)
{
setupUi(this);
d->_ui->setupUi(this);
m_exampleEditor = new QCodeEdit(false, this);
d->m_exampleEditor = new QCodeEdit(false, this);
QHBoxLayout * hb = new QHBoxLayout;
hb->addWidget(m_exampleEditor->editor());
m_exampleGroupBox->setLayout(hb);
m_exampleGroupBox->setVisible(false);
hb->addWidget(d->m_exampleEditor->editor());
d->_ui->m_exampleGroupBox->setLayout(hb);
d->_ui->m_exampleGroupBox->setVisible(false);
}
//! Destroy the widget
@ -82,11 +204,11 @@ CustomSchemeImpl::~CustomSchemeImpl()
*/
void CustomSchemeImpl::setFormatScheme(QFormatScheme * formats)
{
if (formats != m_formats)
if (formats != d->m_formats)
{
m_formats = formats;
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
updateFormatList();
d->m_formats = formats;
d->m_exampleEditor->editor()->document()->setFormatScheme(d->m_formats);
d->updateFormatList();
}
}
@ -96,7 +218,7 @@ void CustomSchemeImpl::setFormatScheme(QFormatScheme * formats)
*/
QFormatScheme * CustomSchemeImpl::formatScheme() const
{
return m_formats;
return d->m_formats;
}
/*!
@ -105,11 +227,11 @@ QFormatScheme * CustomSchemeImpl::formatScheme() const
*/
void CustomSchemeImpl::setExample(const QString & value)
{
if (m_example != value)
if (d->m_example != value)
{
m_example = value;
m_exampleEditor->editor()->setText(m_example);
m_exampleGroupBox->setVisible(! m_example.isEmpty());
d->m_example = value;
d->m_exampleEditor->editor()->setText(d->m_example);
d->_ui->m_exampleGroupBox->setVisible(! d->m_example.isEmpty());
}
}
@ -120,7 +242,7 @@ void CustomSchemeImpl::setExample(const QString & value)
*/
const QString & CustomSchemeImpl::example() const
{
return m_example;
return d->m_example;
}
/*!
@ -129,9 +251,9 @@ const QString & CustomSchemeImpl::example() const
*/
void CustomSchemeImpl::setLanguageFactory(QLanguageFactory * value)
{
if (value != m_languageFactory)
if (value != d->m_languageFactory)
{
m_languageFactory = value;
d->m_languageFactory = value;
}
}
@ -141,7 +263,7 @@ void CustomSchemeImpl::setLanguageFactory(QLanguageFactory * value)
*/
QLanguageFactory * CustomSchemeImpl::languageFactory() const
{
return m_languageFactory;
return d->m_languageFactory;
}
/*!
@ -150,9 +272,9 @@ QLanguageFactory * CustomSchemeImpl::languageFactory() const
*/
void CustomSchemeImpl::setLanguageDefinition(const QString & value)
{
if (m_languageFactory)
if (d->m_languageFactory)
{
m_languageFactory->setLanguage(m_exampleEditor->editor(), value);
d->m_languageFactory->setLanguage(d->m_exampleEditor->editor(), value);
}
}
@ -163,8 +285,8 @@ void CustomSchemeImpl::setLanguageDefinition(const QString & value)
*/
QString CustomSchemeImpl::languageDefinition() const
{
if (m_exampleEditor->editor()->languageDefinition())
return m_exampleEditor->editor()->languageDefinition()->language();
if (d->m_exampleEditor->editor()->languageDefinition())
return d->m_exampleEditor->editor()->languageDefinition()->language();
else
return QString();
}
@ -175,10 +297,10 @@ QString CustomSchemeImpl::languageDefinition() const
*/
void CustomSchemeImpl::setHiddenFormat(const QStringList & value)
{
if (m_hiddenFormat != value)
if (d->m_hiddenFormat != value)
{
m_hiddenFormat = value;
updateFormatList();
d->m_hiddenFormat = value;
d->updateFormatList();
}
}
@ -189,115 +311,7 @@ void CustomSchemeImpl::setHiddenFormat(const QStringList & value)
*/
const QStringList & CustomSchemeImpl::hiddenFormat() const
{
return m_hiddenFormat;
}
void CustomSchemeImpl::on_m_formatsListView_currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)
{
if (current != m_currentItem)
{
m_currentItem = current;
if (m_currentItem && m_formats)
{
m_currentFormat = &(m_formats->formatRef(m_currentItem->text()));
m_boldCheckBox->setChecked(m_currentFormat->weight != QFont::Normal);
m_overLineCheckBox->setChecked(m_currentFormat->overline);
m_strikeOutCheckBox->setChecked(m_currentFormat->strikeout);
m_italicCheckBox->setChecked(m_currentFormat->italic);
m_underLineCheckBox->setChecked(m_currentFormat->underline || m_currentFormat->waveUnderline);
m_waveUnderLineCheckBox->setChecked(m_currentFormat->waveUnderline);
m_foreGroundComboBox->setColor(m_currentFormat->foreground);
m_backGroundComboBox->setColor(m_currentFormat->background);
}
m_formatGroupBox->setEnabled(m_currentItem);
m_colorGroupBox->setEnabled(m_currentItem);
m_exampleGroupBox->setEnabled(m_currentItem);
}
}
void CustomSchemeImpl::on_m_boldCheckBox_stateChanged(int state)
{
if (state == Qt::Checked)
m_currentFormat->weight = QFont::Bold;
else
m_currentFormat->weight = QFont::Normal;
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImpl::on_m_overLineCheckBox_stateChanged(int state)
{
m_currentFormat->overline = state == Qt::Checked;
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImpl::on_m_strikeOutCheckBox_stateChanged(int state)
{
m_currentFormat->strikeout = state == Qt::Checked;
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImpl::on_m_italicCheckBox_stateChanged(int state)
{
m_currentFormat->italic = state == Qt::Checked;
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImpl::on_m_underLineCheckBox_stateChanged(int state)
{
m_currentFormat->underline = (state == Qt::Checked) && (m_waveUnderLineCheckBox->isChecked() == Qt::Unchecked);
m_currentFormat->waveUnderline = (state == Qt::Checked) && (m_waveUnderLineCheckBox->isChecked() == Qt::Checked);
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImpl::on_m_waveUnderLineCheckBox_stateChanged(int state)
{
m_currentFormat->underline = m_underLineCheckBox->isChecked() && (state == Qt::Unchecked);
m_currentFormat->waveUnderline = m_underLineCheckBox->isChecked() && (state == Qt::Checked);
m_currentItem->setFont(m_currentFormat->toTextCharFormat().font());
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImpl::on_m_foreGroundComboBox_activated(const QColor &col)
{
m_currentFormat->foreground = col;
if (m_currentFormat->background.isValid()) m_currentItem->setBackground(m_currentFormat->background);
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImpl::on_m_backGroundComboBox_activated(const QColor &col)
{
m_currentFormat->background = col;
if (m_currentFormat->foreground.isValid()) m_currentItem->setForeground(m_currentFormat->foreground);
m_exampleEditor->editor()->document()->setFormatScheme(m_formats);
}
void CustomSchemeImpl::updateFormatList()
{
m_formatsListView->clear();
if (m_formats)
{
foreach(const QString & f, m_formats->formats())
{
QFormat format = m_formats->format(f);
QListWidgetItem * item = new QListWidgetItem(f, m_formatsListView);
if (format.background.isValid()) item->setBackground(format.background);
if (format.foreground.isValid()) item->setForeground(format.foreground);
item->setFont(format.toTextCharFormat().font());
item->setHidden(m_hiddenFormat.contains(f));
}
}
if (m_formatsListView->count())
m_formatsListView->setCurrentRow(0);
return d->m_hiddenFormat;
}

27
components/customschemeimpl.h

@ -22,15 +22,18 @@
#define _CUSTOMSCHEMEIMPL_H_
// Xinx header
#include "ui_customscheme.h"
#include <components-config.h>
// Qt header
#include <QWidget>
class CustomSchemeImplPrivate;
class QCodeEdit;
class QFormatScheme;
class QFormat;
class QLanguageFactory;
class COMPONENTSEXPORT CustomSchemeImpl : public QWidget, public Ui::CustomScheme
class COMPONENTSEXPORT CustomSchemeImpl : public QWidget
{
Q_OBJECT
Q_CLASSINFO("Author", "Ulrich Van Den Hekke")
@ -58,26 +61,8 @@ public:
void setHiddenFormat(const QStringList & value);
const QStringList & hiddenFormat() const;
private slots:
void on_m_formatsListView_currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous);
void on_m_boldCheckBox_stateChanged(int state);
void on_m_overLineCheckBox_stateChanged(int state);
void on_m_strikeOutCheckBox_stateChanged(int state);
void on_m_italicCheckBox_stateChanged(int state);
void on_m_underLineCheckBox_stateChanged(int state);
void on_m_waveUnderLineCheckBox_stateChanged(int state);
void on_m_foreGroundComboBox_activated(const QColor &col);
void on_m_backGroundComboBox_activated(const QColor &col);
private:
void updateFormatList();
QLanguageFactory * m_languageFactory;
QCodeEdit * m_exampleEditor;
QFormatScheme * m_formats;
QFormat * m_currentFormat;
QListWidgetItem * m_currentItem;
QString m_example;
QStringList m_hiddenFormat;
QScopedPointer<CustomSchemeImplPrivate> d;
};
#endif /* _CUSTOMSCHEMEIMPL_H_ */

63
components/customschemeimpl_p.h

@ -0,0 +1,63 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
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
#ifndef _CUSTOMSCHEMEIMPL_P_H_
#define _CUSTOMSCHEMEIMPL_P_H_
#include "customschemeimpl.h"
#include <QObject>
#include <QListWidgetItem>
#include "ui_customscheme.h"
class QCodeEdit;
class QFormatScheme;
class QFormat;
class QLanguageFactory;
class CustomSchemeImplPrivate : public QObject
{
Q_OBJECT
public slots:
void on_m_formatsListView_currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous);
void on_m_boldCheckBox_stateChanged(int state);
void on_m_overLineCheckBox_stateChanged(int state);
void on_m_strikeOutCheckBox_stateChanged(int state);
void on_m_italicCheckBox_stateChanged(int state);
void on_m_underLineCheckBox_stateChanged(int state);
void on_m_waveUnderLineCheckBox_stateChanged(int state);
void on_m_foreGroundComboBox_activated(const QColor &col);
void on_m_backGroundComboBox_activated(const QColor &col);
public:
CustomSchemeImplPrivate();
virtual ~CustomSchemeImplPrivate();
void updateFormatList();
QScopedPointer<Ui::CustomScheme> _ui;
QLanguageFactory * m_languageFactory;
QCodeEdit * m_exampleEditor;
QFormatScheme * m_formats;
QFormat * m_currentFormat;
QListWidgetItem * m_currentItem;
QString m_example;
QStringList m_hiddenFormat;
};
#endif /* _CUSTOMSCHEMEIMPL_P_H_ */

393
components/directoryedit.cpp

@ -18,7 +18,8 @@
*/
// Xinx header
#include "directoryedit.h"
#include "directoryedit_p.h"
#include "completerdirmodel.h"
// Qt header
#include <QFile>
@ -30,61 +31,81 @@
#include <QToolButton>
#include <QKeyEvent>
/* CompleterDirModel */
/* DirectoryEditPrivate */
/*!
* \ingroup Components
* \class CompleterDirModel
* \since 0.7.0.0
*
* \brief Class used by DirectoryEdit to complete on path.
*
* Completer model class based on a QDirModel which permit to propose a completion on
* the path.
* The CompleterDirModel convert path on native separtor. If the path end with a separator,
* the separator is deleted.
*
* To use this modele, we can use a QCompleter on a QLineEdit.
*
* \code
* QLineEdit * lineEdit = new QLineEdit;
*
* QCompleter * completer = new QCompleter(lineEdit);
* lineEdit->setCompleter(completer);
*
* CompleterDirModel * model = new CompleterDirModel(completer);
* completer->setModel(model);
* \endcode
*/
DirectoryEditPrivate::DirectoryEditPrivate(DirectoryEdit* parent) : _parent(parent), m_error(false), m_directory(true), m_fileMustExist(true), m_ignoreCursorPositionChanged(false)
{
}
/*!
* \brief Construct a CompleterDirModel.
* \param parent The parent of the object.
*/
CompleterDirModel::CompleterDirModel(QObject *parent) : QDirModel(parent)
* \internal
*/
void DirectoryEditPrivate::slotEditorCursorPositionChanged(int oldpos, int newpos)
{
if (!_parent->hasSelectedText() && !m_ignoreCursorPositionChanged)
{
m_ignoreCursorPositionChanged = true;
bool allowSelection = true;
int pos = -1;
if (newpos < m_prefix.size() && newpos != 0)
{
if (oldpos == 0)
{
allowSelection = false;
pos = m_prefix.size();
}
else
{
pos = oldpos;
}
}
if (pos != -1)
{
const int selSize = _parent->selectionStart() >= 0 && allowSelection ? (_parent->selectedText().size() * (newpos < pos ? -1 : 1)) - newpos + pos : 0;
const bool wasBlocked = blockSignals(true);
if (selSize != 0)
{
_parent->setSelection(pos - selSize, selSize);
}
else
{
_parent->setCursorPosition(pos);
}
blockSignals(wasBlocked);
}
m_ignoreCursorPositionChanged = false;
}
}
/*!
* \brief Return the data to change in the completion dir model.
*
* This model show the good separator (with the \p QDir::toNativeSepartors() function).
* \param index The model index, represents a path in the tree.
* \param role Only the role Qt::DisplayRole is modified in this object.
*/
QVariant CompleterDirModel::data(const QModelIndex &index, int role) const
* \brief Slot called when the text changed.
*
* This method change the color of the text if the directory \p text not exist.
*/
void DirectoryEditPrivate::slotTextChanged(QString text)
{
if (role == Qt::DisplayRole && index.column() == 0)
QFileInfo fileInfo(text);
QFile file(text);
QPalette palette(_parent->palette());
m_error = (m_directory != fileInfo.isDir()) || (m_fileMustExist && !file.exists());
if (!m_error)
{
QString path = QDir::toNativeSeparators(filePath(index));
if (path.endsWith(QDir::separator()))
path.chop(1);
return path;
palette.setColor(QPalette::Text, QColor());
}
return QDirModel::data(index, role);
else
{
palette.setColor(QPalette::Text, Qt::red);
}
_parent->setPalette(palette);
}
/* DirectoryEdit */
/*!
@ -114,10 +135,10 @@ QVariant CompleterDirModel::data(const QModelIndex &index, int role) const
* \brief Construct a DirectoryEdit object.
* \param parent The parent widget of the object.
*/
DirectoryEdit::DirectoryEdit(QWidget * parent) : QLineEdit(parent), m_error(false), m_directory(true), m_fileMustExist(true), m_ignoreCursorPositionChanged(false)
DirectoryEdit::DirectoryEdit(QWidget * parent) : QLineEdit(parent), d(new DirectoryEditPrivate)
{
connect(this, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
connect(this, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(slotEditorCursorPositionChanged(int,int)));
connect(this, SIGNAL(textChanged(QString)), d.data(), SLOT(slotTextChanged(QString)));
connect(this, SIGNAL(cursorPositionChanged(int,int)), d.data(), SLOT(slotEditorCursorPositionChanged(int,int)));
QCompleter * completer = new QCompleter(this);
this->setCompleter(completer);
completer->setModel(new CompleterDirModel(completer));
@ -128,10 +149,18 @@ DirectoryEdit::DirectoryEdit(QWidget * parent) : QLineEdit(parent), m_error(fals
* \param contents Content of the Line edit.
* \param parent The parent widget of the object.
*/
DirectoryEdit::DirectoryEdit(const QString & contents, QWidget * parent) : QLineEdit(contents, parent), m_error(false), m_directory(true), m_fileMustExist(true), m_ignoreCursorPositionChanged(false)
DirectoryEdit::DirectoryEdit(const QString & contents, QWidget * parent) : QLineEdit(contents, parent), d(new DirectoryEditPrivate)
{
connect(this, SIGNAL(textChanged(QString)), d.data(), SLOT(slotTextChanged(QString)));
connect(this, SIGNAL(cursorPositionChanged(int,int)), d.data(), SLOT(slotEditorCursorPositionChanged(int,int)));
}
/*!
* \brief Destroy the DirectoryEdit
*/
DirectoryEdit::~DirectoryEdit()
{
connect(this, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
connect(this, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(slotEditorCursorPositionChanged(int,int)));
}
/*!
@ -141,10 +170,10 @@ DirectoryEdit::DirectoryEdit(const QString & contents, QWidget * parent) : QLine
*/
void DirectoryEdit::setFileMustExist(bool value)
{
if (value != m_fileMustExist)
if (value != d->m_fileMustExist)
{
m_fileMustExist = value;
slotTextChanged(this->text());
d->m_fileMustExist = value;
d->slotTextChanged(this->text());
}
}
@ -154,7 +183,7 @@ void DirectoryEdit::setFileMustExist(bool value)
*/
bool DirectoryEdit::fileMustExist() const
{
return m_fileMustExist;
return d->m_fileMustExist;
}
/*!
@ -164,7 +193,7 @@ bool DirectoryEdit::fileMustExist() const
*/
void DirectoryEdit::setFilter(const QString & filter)
{
m_filter = filter;
d->m_filter = filter;
}
/*!
@ -173,7 +202,7 @@ void DirectoryEdit::setFilter(const QString & filter)
*/
const QString & DirectoryEdit::filter() const
{
return m_filter;
return d->m_filter;
}
/*!
@ -186,9 +215,9 @@ const QString & DirectoryEdit::filter() const
*/
void DirectoryEdit::setPrefix(const QString & value)
{
if (m_prefix != value)
if (d->m_prefix != value)
{
m_prefix = value;
d->m_prefix = value;
setText(text());
}
}
@ -199,7 +228,7 @@ void DirectoryEdit::setPrefix(const QString & value)
*/
const QString & DirectoryEdit::prefix() const
{
return m_prefix;
return d->m_prefix;
}
/*!
@ -208,7 +237,7 @@ const QString & DirectoryEdit::prefix() const
*/
bool DirectoryEdit::isDirectory() const
{
return m_directory;
return d->m_directory;
}
/*!
@ -221,10 +250,10 @@ bool DirectoryEdit::isDirectory() const
*/
void DirectoryEdit::setDirectory(bool value)
{
if (m_directory != value)
if (d->m_directory != value)
{
m_directory = value;
slotTextChanged(text());
d->m_directory = value;
d->slotTextChanged(text());
}
}
@ -236,7 +265,7 @@ void DirectoryEdit::setDirectory(bool value)
*/
bool DirectoryEdit::isError() const
{
return m_error;
return d->m_error;
}
/*!
@ -244,13 +273,13 @@ bool DirectoryEdit::isError() const
*/
void DirectoryEdit::setText(const QString & value)
{
if (value.startsWith(m_prefix))
if (value.startsWith(d->m_prefix))
{
QLineEdit::setText(value);
}
else
{
QLineEdit::setText(m_prefix + value);
QLineEdit::setText(d->m_prefix + value);
}
}
@ -259,7 +288,7 @@ void DirectoryEdit::setText(const QString & value)
*/
void DirectoryEdit::selectAll()
{
setSelection(m_prefix.size(), text().size() - m_prefix.size());
setSelection(d->m_prefix.size(), text().size() - d->m_prefix.size());
}
/*!
@ -267,8 +296,8 @@ void DirectoryEdit::selectAll()
*/
void DirectoryEdit::clear()
{
setText(m_prefix);
setCursorPosition(m_prefix.size());
setText(d->m_prefix);
setCursorPosition(d->m_prefix.size());
}
/*!
@ -276,8 +305,8 @@ void DirectoryEdit::clear()
*/
void DirectoryEdit::keyPressEvent(QKeyEvent *event)
{
if (!event->text().isEmpty() && cursorPosition() < m_prefix.size())
setCursorPosition(m_prefix.size());
if (!event->text().isEmpty() && cursorPosition() < d->m_prefix.size())
setCursorPosition(d->m_prefix.size());
switch (event->key())
{
@ -289,7 +318,7 @@ void DirectoryEdit::keyPressEvent(QKeyEvent *event)
const QString text = displayText();
if (event->key() == Qt::Key_End)
{
if (currentPos == 0 && !m_prefix.isEmpty())
if (currentPos == 0 && !d->m_prefix.isEmpty())
{
break; // let lineedit handle this
}
@ -300,13 +329,13 @@ void DirectoryEdit::keyPressEvent(QKeyEvent *event)
}
else
{
if (currentPos <= m_prefix.size())
if (currentPos <= d->m_prefix.size())
{
break; // let lineedit handle this
}
else
{
setSelection(currentPos, m_prefix.size() - currentPos);
setSelection(currentPos, d->m_prefix.size() - currentPos);
}
}
event->accept();
@ -314,7 +343,7 @@ void DirectoryEdit::keyPressEvent(QKeyEvent *event)
}
break;
case Qt::Key_Backspace:
if (cursorPosition() == m_prefix.size())
if (cursorPosition() == d->m_prefix.size())
{
event->ignore();
return;
@ -345,76 +374,6 @@ void DirectoryEdit::keyPressEvent(QKeyEvent *event)
QLineEdit::keyPressEvent(event);
}
/*!
* \internal
*/
void DirectoryEdit::slotEditorCursorPositionChanged(int oldpos, int newpos)
{
if (!hasSelectedText() && !m_ignoreCursorPositionChanged)
{
m_ignoreCursorPositionChanged = true;
bool allowSelection = true;
int pos = -1;
if (newpos < m_prefix.size() && newpos != 0)
{
if (oldpos == 0)
{
allowSelection = false;
pos = m_prefix.size();
}
else
{
pos = oldpos;
}
}
if (pos != -1)
{
const int selSize = selectionStart() >= 0 && allowSelection
? (selectedText().size() * (newpos < pos ? -1 : 1)) - newpos + pos
: 0;
const bool wasBlocked = blockSignals(true);
if (selSize != 0)
{
setSelection(pos - selSize, selSize);
}
else
{
setCursorPosition(pos);
}
blockSignals(wasBlocked);
}
m_ignoreCursorPositionChanged = false;
}
}
/*!
* \brief Slot called when the text changed.
*
* This method change the color of the text if the directory \p text not exist.
*/
void DirectoryEdit::slotTextChanged(QString text)
{
QFileInfo fileInfo(text);
QFile file(text);
QPalette palette(this->palette());
m_error = (m_directory != fileInfo.isDir()) || (m_fileMustExist && !file.exists());
if (!m_error)
{
palette.setColor(QPalette::Text, QColor());
}
else
{
palette.setColor(QPalette::Text, Qt::red);
}
setPalette(palette);
}
/*!
* \brief Open a dialog to change the path in the line editor.
* \param parent The parent windows of the dialog to open
@ -425,151 +384,15 @@ void DirectoryEdit::changePath(QWidget * parent, const QString & defaultValue)
QString value = this->text();
if (value.isEmpty()) value = defaultValue;
if (m_directory)
if (d->m_directory)
value = QFileDialog::getExistingDirectory(parent, tr("Change the path"), value);
else if (m_fileMustExist)
value = QFileDialog::getOpenFileName(parent, tr("Change the file"), value, m_filter, &m_filter);
else if (d->m_fileMustExist)
value = QFileDialog::getOpenFileName(parent, tr("Change the file"), value, d->m_filter, &d->m_filter);
else
value = QFileDialog::getSaveFileName(parent, tr("Change the file"), value, m_filter, &m_filter);
value = QFileDialog::getSaveFileName(parent, tr("Change the file"), value, d->m_filter, &d->m_filter);
if (! value.isEmpty())
{
this->setText(QDir::toNativeSeparators(value));
}
}
/* PrivateDirectoryEditWidget */
class PrivateDirectoryEditWidget
{
public:
PrivateDirectoryEditWidget(QWidget * o);
DirectoryEdit * m_lineEdit;
QToolButton * m_button;
QString m_default;
private:
};
PrivateDirectoryEditWidget::PrivateDirectoryEditWidget(QWidget * o)
{
QHBoxLayout * layout = new QHBoxLayout(o);
m_lineEdit = new DirectoryEdit(o);
m_button = new QToolButton(o);
m_button->setIcon(QIcon(":/images/folder.png"));
layout->addWidget(m_lineEdit);
layout->addWidget(m_button);
layout->setMargin(0);
}
/* DirectoryEditWidget */
/*!
* \ingroup Components
* \class DirectoryEditWidget
* \since 0.7.0.0
*
* \brief A widget to edit a path. This widget has a button attached to open a dialog.
*
* This class is an association of a Directory Line editor and a button.
* The button call the \p changePath slot from the \p DirectoryEdit class.
*
* \image html directoryeditwidget1.png
* \image latex directoryeditwidget1.png
*/
/*!
* \brief Constructs the directory edit widget and tells if the widget is used
* to edit directory or file.
* \param isDirectory If \p true, the widget edit directory, otherwise file.
* \param parent The parent of the widget.
*/
DirectoryEditWidget::DirectoryEditWidget(bool isDirectory, QWidget * parent) : QWidget(parent)
{
d = new PrivateDirectoryEditWidget(this);
d->m_lineEdit->setDirectory(isDirectory);
connect(d->m_button, SIGNAL(clicked()), this, SLOT(changePath()));
}
/*!
* \brief Construct the directory edit widget.
* \param parent The parent of the object.
*/
DirectoryEditWidget::DirectoryEditWidget(QWidget * parent) : QWidget(parent)
{
d = new PrivateDirectoryEditWidget(this);
connect(d->m_button, SIGNAL(clicked()), this, SLOT(changePath()));
}
//! Destroy the widget
DirectoryEditWidget::~DirectoryEditWidget()
{
delete d;
}
/*!
* \brief This property holds whether the input is a directory or a file
*
* Return true if the widget is used to edit directory, or false if the widget is used
* to edit file.
* \sa setDirectory()
*/
bool DirectoryEditWidget::isDirectory() const
{
return d->m_lineEdit->isDirectory();
}
/*!
* \brief Change the directory/files goal of the widget.
* \param value If \p true, the widget is used for edit directory, otherwise files.
* \sa isDirectory()
*/
void DirectoryEditWidget::setDirectory(bool value)
{
d->m_lineEdit->setDirectory(value);
}
/*!
* \brief Return the default value used by the widget when the user click on the open button
* \sa setDefaultValue()
*/
QString DirectoryEditWidget::defaultValue() const
{
return d->m_default;
}
/*!
* \brief Used to change the default value to use, when no text is in the editor.
* \param value The new default value to use when the user click on the button.
* \sa defaultValue()
*/
void DirectoryEditWidget::setDefaultValue(const QString & value)
{