Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add custom widget for QgsFontButton
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent bacad8c commit e2acf53
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/customwidgets/CMakeLists.txt
Expand Up @@ -25,6 +25,7 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
qgsfieldexpressionwidgetplugin.cpp
qgsfilewidgetplugin.cpp
qgsfilterlineeditplugin.cpp
qgsfontbuttonplugin.cpp
qgsmaplayercomboboxplugin.cpp
qgsopacitywidgetplugin.cpp
qgspasswordlineeditplugin.cpp
Expand Down Expand Up @@ -54,6 +55,7 @@ SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
qgsfieldexpressionwidgetplugin.h
qgsfilewidgetplugin.h
qgsfilterlineeditplugin.h
qgsfontbuttonplugin.h
qgsmaplayercomboboxplugin.h
qgsopacitywidgetplugin.h
qgspasswordlineeditplugin.h
Expand Down
2 changes: 2 additions & 0 deletions src/customwidgets/qgiscustomwidgets.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgsfieldexpressionwidgetplugin.h"
#include "qgsfilewidgetplugin.h"
#include "qgsfilterlineeditplugin.h"
#include "qgsfontbuttonplugin.h"
#include "qgsmaplayercomboboxplugin.h"
#include "qgsopacitywidgetplugin.h"
#include "qgspasswordlineeditplugin.h"
Expand Down Expand Up @@ -57,6 +58,7 @@ QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
mWidgets.append( new QgsFieldExpressionWidgetPlugin( this ) );
mWidgets.append( new QgsFileWidgetPlugin( this ) );
mWidgets.append( new QgsFilterLineEditPlugin( this ) );
mWidgets.append( new QgsFontButtonPlugin( this ) );
mWidgets.append( new QgsMapLayerComboBoxPlugin( this ) );
mWidgets.append( new QgsOpacityWidgetPlugin( this ) );
mWidgets.append( new QgsPasswordLineEditPlugin( this ) );
Expand Down
97 changes: 97 additions & 0 deletions src/customwidgets/qgsfontbuttonplugin.cpp
@@ -0,0 +1,97 @@
/***************************************************************************
qgsfontbuttonplugin.cpp
----------------------
Date : 06.07.2017
Copyright : (C) 2017 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgiscustomwidgets.h"
#include "qgsfontbuttonplugin.h"
#include "qgsfontbutton.h"


QgsFontButtonPlugin::QgsFontButtonPlugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}


QString QgsFontButtonPlugin::name() const
{
return "QgsFontButton";
}

QString QgsFontButtonPlugin::group() const
{
return QgisCustomWidgets::groupName();
}

QString QgsFontButtonPlugin::includeFile() const
{
return "qgsfontbutton.h";
}

QIcon QgsFontButtonPlugin::icon() const
{
return QIcon( ":/images/icons/qgis-icon-60x60.png" );
}

bool QgsFontButtonPlugin::isContainer() const
{
return false;
}

QWidget *QgsFontButtonPlugin::createWidget( QWidget *parent )
{
return new QgsFontButton( parent );
}

bool QgsFontButtonPlugin::isInitialized() const
{
return mInitialized;
}

void QgsFontButtonPlugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}


QString QgsFontButtonPlugin::toolTip() const
{
return tr( "Select font" );
}

QString QgsFontButtonPlugin::whatsThis() const
{
return "";
}

QString QgsFontButtonPlugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mFontButton\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>27</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
51 changes: 51 additions & 0 deletions src/customwidgets/qgsfontbuttonplugin.h
@@ -0,0 +1,51 @@
/***************************************************************************
qgsfontbuttonplugin.h
--------------------
Date : 06.07.2017
Copyright : (C) 2017 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSFONTBUTTONPLUGIN_H
#define QGSFONTBUTTONPLUGIN_H


#include <QtGlobal>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
#include <QtUiPlugin/QDesignerExportWidget>
#include "qgis_customwidgets.h"


class CUSTOMWIDGETS_EXPORT QgsFontButtonPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
explicit QgsFontButtonPlugin( QObject *parent = 0 );

private:
bool mInitialized;

// QDesignerCustomWidgetInterface interface
public:
QString name() const override;
QString group() const override;
QString includeFile() const override;
QIcon icon() const override;
bool isContainer() const override;
QWidget *createWidget( QWidget *parent ) override;
bool isInitialized() const override;
void initialize( QDesignerFormEditorInterface *core ) override;
QString toolTip() const override;
QString whatsThis() const override;
QString domXml() const override;
};
#endif // QGSFONTBUTTONPLUGIN_H

0 comments on commit e2acf53

Please sign in to comment.