From 2998d9d3d5dfc825904b53393e9ae12e7cd5b72b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 21 Apr 2015 15:44:54 +0200 Subject: Moved Console to client. It's part of the demo application. --- examples/client/CMakeLists.txt | 2 +- examples/client/console.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++ examples/client/console.h | 42 +++++++++++++++++++++++ examples/client/main.cpp | 6 ++-- 4 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 examples/client/console.cpp create mode 100644 examples/client/console.h (limited to 'examples') diff --git a/examples/client/CMakeLists.txt b/examples/client/CMakeLists.txt index 3555b3e..97b5ad2 100644 --- a/examples/client/CMakeLists.txt +++ b/examples/client/CMakeLists.txt @@ -2,7 +2,7 @@ project(akonadi2_client) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -add_executable(${PROJECT_NAME} main.cpp) +add_executable(${PROJECT_NAME} main.cpp console.cpp) target_link_libraries(${PROJECT_NAME} akonadi2common) qt5_use_modules(${PROJECT_NAME} Widgets Network) install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/examples/client/console.cpp b/examples/client/console.cpp new file mode 100644 index 0000000..8b4f1a5 --- /dev/null +++ b/examples/client/console.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "console.h" + +#include +#include +#include +#include + +static Console *s_console = 0; + +Console *Console::main() +{ + if (!s_console) { + s_console = new Console(QString()); + } + return s_console; +} + +Console::Console(const QString &title) + : QWidget(0) +{ + if (!s_console) { + s_console = this; + } + + resize(1000, 1500); + + QVBoxLayout *topLayout = new QVBoxLayout(this); + + QLabel *titleLabel = new QLabel(this); + titleLabel->setText(title); + QFont font = titleLabel->font(); + font.setWeight(QFont::Bold); + titleLabel->setFont(font); + titleLabel->setAlignment(Qt::AlignCenter); + + QFont consoleFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); + consoleFont.setPointSize(7); + m_textDisplay = new QTextBrowser(this); + m_textDisplay->document()->setDefaultFont(consoleFont); + topLayout->addWidget(titleLabel); + topLayout->addWidget(m_textDisplay, 10); + + show(); + m_timestamper.start(); +} + +Console::~Console() +{ + +} + +void Console::log(const QString &message) +{ + m_textDisplay->append(QString::number(m_timestamper.elapsed()).rightJustified(6) + ": " + message); +} + diff --git a/examples/client/console.h b/examples/client/console.h new file mode 100644 index 0000000..a6fef01 --- /dev/null +++ b/examples/client/console.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include +#include + +class QTextBrowser; + +class Console : public QWidget +{ + Q_OBJECT +public: + static Console *main(); + Console(const QString &title); + ~Console(); + + void log(const QString &message); + +private: + QTextBrowser *m_textDisplay; + QTime m_timestamper; + static Console *s_output; +}; diff --git a/examples/client/main.cpp b/examples/client/main.cpp index b4cb081..5cd6141 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -21,15 +21,15 @@ #include #include "common/commands.h" -#include "common/console.h" #include "common/resourceaccess.h" +#include "console.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); - new Akonadi2::Console("Akonadi2 Client"); - Akonadi2::Console::main()->log(QString("PID: %1").arg(QCoreApplication::applicationPid())); + new Console("Akonadi2 Client"); + Console::main()->log(QString("PID: %1").arg(QCoreApplication::applicationPid())); QCommandLineParser cliOptions; cliOptions.addPositionalArgument(QObject::tr("[resource]"), -- cgit v1.2.3