Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Reformat to current usual KDE code style

parent 2ebc80e2
......@@ -43,7 +43,8 @@
KUIViewer::KUIViewer()
: KParts::MainWindow()
{
setObjectName( "KUIViewer" );
setObjectName("KUIViewer");
// setup our actions
setupActions();
......@@ -56,27 +57,23 @@ KUIViewer::KUIViewer()
// name which is a bad idea usually.. but it's alright in this
// case since our Part is made for this Shell
KPluginFactory* factory = KPluginLoader("kuiviewerpart").factory();
if (factory)
{
if (factory) {
// now that the Part is loaded, we cast it to a Part to get
// our hands on it
m_part = factory->create<KParts::ReadOnlyPart>(this);
if (m_part)
{
m_part->setObjectName( "kuiviewer_part" );
if (m_part) {
m_part->setObjectName("kuiviewer_part");
// tell the KParts::MainWindow that this is indeed the main widget
setCentralWidget(m_part->widget());
// and integrate the part's GUI with the shell's
createGUI(m_part);
}
}
else
{
} else {
// if we couldn't find our Part, we exit since the Shell by
// itself can't do anything useful
//FIXME improve message, which Part is this referring to?
//FIXME improve message, which Part is this referring to?
KMessageBox::error(this, i18n("Unable to locate Kuiviewer kpart."));
QApplication::quit();
// we return here, cause kapp->quit() only means "exit the
......@@ -89,9 +86,9 @@ KUIViewer::~KUIViewer()
{
}
void KUIViewer::load(const QUrl &url)
void KUIViewer::load(const QUrl& url)
{
m_part->openUrl( url );
m_part->openUrl(url);
adjustSize();
}
......@@ -107,34 +104,34 @@ void KUIViewer::fileOpen()
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
// button is clicked
QUrl file_name =
QFileDialog::getOpenFileUrl( this, QString(), QUrl(), i18n("*.ui *.UI|User Interface Files") );
QFileDialog::getOpenFileUrl(this, QString(), QUrl(), i18n("*.ui *.UI|User Interface Files"));
if (file_name.isEmpty() == false)
{
if (!file_name.isEmpty()) {
// About this function, the style guide (
// http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
// says that it should open a new window if the document is _not_
// in its initial state. This is what we do here..
if ( m_part->url().isEmpty() )
{
if (m_part->url().isEmpty()) {
// we open the file in this window...
load( file_name );
}
else
{
load(file_name);
} else {
// we open the file in a new window...
KUIViewer* newWin = new KUIViewer;
newWin->load( file_name );
newWin->load(file_name);
newWin->show();
}
}
}
void KUIViewer::takeScreenshot(const QByteArray &filename, int w, int h){
if(!m_part)
void KUIViewer::takeScreenshot(const QByteArray& filename, int w, int h)
{
if (!m_part) {
return;
}
showMinimized();
if(w!=-1 && h!=-1){
if (w != -1 && h != -1) {
// resize widget to the desired size
m_part->widget()->setMinimumSize(w, h);
m_part->widget()->setMaximumSize(w, h);
......@@ -142,9 +139,9 @@ void KUIViewer::takeScreenshot(const QByteArray &filename, int w, int h){
// resize app to be as large as desired size
adjustSize();
// Disable the saving of the size
setAutoSaveSettings(QString::fromLatin1("MainWindow"), false);
setAutoSaveSettings(QStringLiteral("MainWindow"), false);
}
QPixmap pixmap = QPixmap::grabWidget( m_part->widget() );
pixmap.save( filename, "PNG" );
}
QPixmap pixmap = QPixmap::grabWidget(m_part->widget());
pixmap.save(filename, "PNG");
}
......@@ -28,7 +28,8 @@
class KToggleAction;
namespace KParts {
namespace KParts
{
class ReadOnlyPart;
}
......@@ -44,6 +45,7 @@ class ReadOnlyPart;
class KUIViewer : public KParts::MainWindow
{
Q_OBJECT
public:
/**
* Default Constructor
......@@ -58,7 +60,7 @@ public:
/**
* Use this method to load whatever file/URL you have
*/
void load(const QUrl &url);
void load(const QUrl& url);
/**
* Take screenshot of current ui file
......@@ -66,7 +68,7 @@ public:
* @param h height of image
* @param w width of image
*/
void takeScreenshot(const QByteArray &filename, int h=-1, int w=-1);
void takeScreenshot(const QByteArray& filename, int h = -1, int w = -1);
private Q_SLOTS:
void fileOpen();
......@@ -75,9 +77,9 @@ private:
void setupActions();
private:
KParts::ReadOnlyPart *m_part;
KToggleAction *m_toolbarAction;
KToggleAction *m_statusbarAction;
KParts::ReadOnlyPart* m_part;
KToggleAction* m_toolbarAction;
KToggleAction* m_statusbarAction;
};
#endif // KUIVIEWER_H
......
......@@ -45,26 +45,26 @@
#include <QVBoxLayout>
K_PLUGIN_FACTORY( KUIViewerPartFactory, registerPlugin<KUIViewerPart>(); )
K_PLUGIN_FACTORY(KUIViewerPartFactory, registerPlugin<KUIViewerPart>();)
KUIViewerPart::KUIViewerPart( QWidget *parentWidget,
QObject *parent,
const QVariantList &/*args*/ )
KUIViewerPart::KUIViewerPart(QWidget* parentWidget,
QObject* parent,
const QVariantList& /*args*/)
: KParts::ReadOnlyPart(parent)
{
// we need an instance
KAboutData about(QStringLiteral("kuiviewerpart"),
i18n("KUIViewerPart"),
QStringLiteral("0.2"),
i18n("Displays Designer's UI files"),
KAboutLicense::LGPL);
i18n("KUIViewerPart"),
QStringLiteral("0.2"),
i18n("Displays Designer's UI files"),
KAboutLicense::LGPL);
about.addAuthor(i18n("Richard Moore"), i18n("Original author"), "rich@kde.org");
about.addAuthor(i18n("Ian Reinhart Geiser"), i18n("Original author"), "geiseri@kde.org");
setComponentData(about);
// this should be your custom internal widget
m_widget = new QWidget( parentWidget );
QVBoxLayout *widgetVBoxLayout = new QVBoxLayout(m_widget);
m_widget = new QWidget(parentWidget);
QVBoxLayout* widgetVBoxLayout = new QVBoxLayout(m_widget);
widgetVBoxLayout->setMargin(0);
// notify the part that this is our internal widget
......@@ -100,6 +100,7 @@ KUIViewerPart::KUIViewerPart( QWidget *parentWidget,
}
}
}
m_style->setToolTip(i18n("Set the style used for the view."));
m_style->setMenuAccelsEnabled(true);
......@@ -121,7 +122,7 @@ KUIViewerPart::~KUIViewerPart()
static QStringList designerPluginPaths()
{
QStringList paths;
const QStringList &libraryPaths = QApplication::libraryPaths();
const QStringList& libraryPaths = QApplication::libraryPaths();
for (const auto& path : libraryPaths) {
paths.append(path + QLatin1String("/designer"));
}
......@@ -131,9 +132,10 @@ static QStringList designerPluginPaths()
bool KUIViewerPart::openFile()
{
// m_file is always local so we can use QFile on it
QFile file( localFilePath() );
if ( !file.open(QIODevice::ReadOnly) )
QFile file(localFilePath());
if (!file.open(QIODevice::ReadOnly)) {
return false;
}
delete m_view;
QFormBuilder builder;
......@@ -143,43 +145,42 @@ bool KUIViewerPart::openFile()
file.close();
updateActions();
if ( !m_view )
return false;
if (!m_view) {
return false;
}
m_view->show();
slotStyle(0);
return true;
}
void KUIViewerPart::updateActions()
{
if ( !m_view.isNull() ) {
m_style->setEnabled( true );
m_copy->setEnabled( true );
}
else {
m_style->setEnabled( false );
m_copy->setEnabled( false );
}
const bool hasView = !m_view.isNull();
m_style->setEnabled(hasView);
m_copy->setEnabled(hasView);
}
void KUIViewerPart::slotStyle(int)
{
if ( m_view.isNull() ) {
updateActions();
return;
if (m_view.isNull()) {
updateActions();
return;
}
QString styleName = m_style->currentText();
QStyle* style = QStyleFactory::create(styleName);
const QString styleName = m_style->currentText();
QStyle* style = QStyleFactory::create(styleName);
qCDebug(KUIVIEWERPART) << "Change style: " << styleName;
m_widget->hide();
QApplication::setOverrideCursor( Qt::WaitCursor );
m_widget->setStyle( style);
QApplication::setOverrideCursor(Qt::WaitCursor);
m_widget->setStyle(style);
QList<QWidget *>l = m_widget->findChildren<QWidget*>();
const QList<QWidget*> l = m_widget->findChildren<QWidget*>();
for (int i = 0; i < l.size(); ++i) {
l.at(i)->setStyle( style );
l.at(i)->setStyle(style);
}
m_widget->show();
......@@ -202,12 +203,12 @@ void KUIViewerPart::slotStyle(int)
void KUIViewerPart::slotGrab()
{
if ( m_view.isNull() ) {
updateActions();
return;
if (m_view.isNull()) {
updateActions();
return;
}
QClipboard *clipboard = QApplication::clipboard();
QClipboard* clipboard = QApplication::clipboard();
clipboard->setPixmap(QPixmap::grabWidget(m_widget));
}
......
......@@ -40,11 +40,12 @@ class KSelectAction;
class KUIViewerPart : public KParts::ReadOnlyPart
{
Q_OBJECT
public:
/**
* Default constructor
*/
KUIViewerPart(QWidget *parentWidget, QObject *parent, const QVariantList &args);
KUIViewerPart(QWidget* parentWidget, QObject* parent, const QVariantList& args);
/**
* Destructor
......@@ -52,9 +53,9 @@ public:
~KUIViewerPart() override;
public Q_SLOTS:
void slotStyle(int);
void slotGrab();
void updateActions();
void slotStyle(int);
void slotGrab();
void updateActions();
protected:
/**
......@@ -63,10 +64,10 @@ protected:
bool openFile() override;
private:
QWidget *m_widget;
QWidget* m_widget;
QPointer<QWidget> m_view;
KSelectAction *m_style;
QAction *m_copy;
KSelectAction* m_style;
QAction* m_copy;
QString m_styleFromConfig;
};
......
......@@ -32,15 +32,15 @@
#include <QCommandLineParser>
#include <QCommandLineOption>
int main(int argc, char **argv)
int main(int argc, char** argv)
{
QApplication app(argc, argv);
KLocalizedString::setApplicationDomain("kuiviewer");
KAboutData about(QStringLiteral("kuiviewer"), i18n("KUIViewer"), QStringLiteral("0.2"),
i18n("Displays Designer's UI files"),
KAboutLicense::LGPL );
i18n("Displays Designer's UI files"),
KAboutLicense::LGPL);
about.addAuthor(i18n("Richard Moore"), i18n("Original author"), "rich@kde.org");
about.addAuthor(i18n("Ian Reinhart Geiser"), i18n("Original author"), "geiseri@kde.org");
// Screenshot capability
......@@ -53,37 +53,33 @@ int main(int argc, char **argv)
parser.addHelpOption();
about.setupCommandLine(&parser);
parser.addPositionalArgument(QLatin1String("[URL]"), i18n( "Document to open" ));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("s") << QLatin1String("takescreenshot"), i18n( "Save screenshot to file and exit" ), QLatin1String("filename")));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("w") << QLatin1String("screenshotwidth"), i18n( "Screenshot width" ), QLatin1String("int"), QLatin1String("-1")));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("h") << QLatin1String("screenshotheight"), i18n( "Screenshot height" ), QLatin1String("int"), QLatin1String("-1")));
parser.addPositionalArgument(QLatin1String("[URL]"), i18n("Document to open"));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("s") << QLatin1String("takescreenshot"), i18n("Save screenshot to file and exit"), QLatin1String("filename")));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("w") << QLatin1String("screenshotwidth"), i18n("Screenshot width"), QLatin1String("int"), QLatin1String("-1")));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("h") << QLatin1String("screenshotheight"), i18n("Screenshot height"), QLatin1String("int"), QLatin1String("-1")));
parser.process(app);
about.processCommandLine(&parser);
// see if we are starting with session management
if (app.isSessionRestored())
if (app.isSessionRestored()) {
RESTORE(KUIViewer)
else
{
} else {
// no session.. just start up normally
if ( parser.positionalArguments().count() == 0 )
{
KUIViewer *widget = new KUIViewer;
if (parser.positionalArguments().isEmpty()) {
KUIViewer* widget = new KUIViewer;
widget->show();
}
else
{
} else {
int i = 0;
for (; i < parser.positionalArguments().count(); i++ ) {
KUIViewer *widget = new KUIViewer;
widget->load( QUrl::fromUserInput(parser.positionalArguments().at(i), QDir::currentPath()) );
for (; i < parser.positionalArguments().count(); i++) {
KUIViewer* widget = new KUIViewer;
widget->load(QUrl::fromUserInput(parser.positionalArguments().at(i), QDir::currentPath()));
if (parser.isSet("takescreenshot")){
if (parser.isSet("takescreenshot")) {
widget->takeScreenshot(parser.value("takescreenshot").toLocal8Bit(),
parser.value("screenshotwidth").toInt(),
parser.value("screenshotheight").toInt());
parser.value("screenshotwidth").toInt(),
parser.value("screenshotheight").toInt());
return 0;
}
widget->show();
......
......@@ -31,38 +31,44 @@
extern "C"
{
Q_DECL_EXPORT ThumbCreator *new_creator()
{
return new QUICreator;
}
Q_DECL_EXPORT ThumbCreator* new_creator()
{
return new QUICreator;
}
bool QUICreator::create(const QString &path, int width, int height, QImage & img)
}
bool QUICreator::create(const QString& path, int width, int height, QImage& img)
{
QStringList designerPluginPaths;
const QStringList &libraryPaths = QCoreApplication::libraryPaths();
for (const auto& path : libraryPaths) {
designerPluginPaths.append(path + QLatin1String("/designer"));
}
QFormBuilder builder;
builder.setPluginPath(designerPluginPaths);
QFile file(path);
if (!file.open(QFile::ReadOnly))
return false;
QWidget *w = builder.load(&file);
file.close();
if ( w )
{
QPixmap p = w->grab();
img = p.toImage().scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
return true;
}
else
return false;
QStringList designerPluginPaths;
const QStringList& libraryPaths = QCoreApplication::libraryPaths();
for (const auto& path : libraryPaths) {
designerPluginPaths.append(path + QLatin1String("/designer"));
}
QFormBuilder builder;
builder.setPluginPath(designerPluginPaths);
QFile file(path);
if (!file.open(QFile::ReadOnly)) {
return false;
}
QWidget* w = builder.load(&file);
file.close();
if (!w) {
return false;
}
const QPixmap p = w->grab();
img = p.toImage().scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
return true;
}
ThumbCreator::Flags QUICreator::flags() const
{
return static_cast<Flags>(DrawFrame);
return DrawFrame;
}
......@@ -28,7 +28,8 @@ class QUICreator : public ThumbCreator
{
public:
QUICreator() {}
bool create(const QString &path, int, int, QImage &img) override;
bool create(const QString& path, int, int, QImage& img) override;
Flags flags() const override;
};
......
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