Commit bfd16f76 authored by Victor Yacovlev's avatar Victor Yacovlev

Start page without WebKit usage (Qt5 only)

parent d27dd02d
#headerBox {
min-height: 50;
background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:0 #99c9ff, stop:1 white);
}
#headerText {
margin: 5;
font-size: 14pt;
font-weight: bold;
color: #115bb2;
}
#programsText, #coursesText, #helpText {
font-size: 12pt;
font-weight: bold;
color: #777777;
qproperty-alignment: "AlignCenter";
margin-bottom: 5;
}
#btnNewProgram, #btnLoadProgram, #btnShowCourses, #btnShowHelp {
border-style: solid;
border-width: 1px;
height: 28px;
font-size: 11pt;
color: #ededed;
}
#btnNewProgram:hover, #btnLoadProgram:hover, #btnShowCourses:hover, #btnShowHelp:hover {
color: white;
}
#btnNewProgram {
background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:0 #ef9331, stop:1 #e9701d);
border-color: #d46400;
border-bottom-width: 0;
}
#btnNewProgram:pressed {
background: #ef9331;
}
#btnLoadProgram:pressed, #btnShowCourses:pressed, #btnShowHelp:pressed {
background: #5699e7;
}
#btnLoadProgram, #btnShowCourses, #btnShowHelp {
background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:0 #5699e7, stop:1 #1a72db);
border-color: #306aaf;
border-bottom-left-radius: 5;
border-bottom-right-radius: 5;
margin-bottom: 10;
}
#btnNewProgram, #btnShowCourses, #btnShowHelp {
border-top-left-radius: 5;
border-top-right-radius: 5;
}
#centralViewScroll {
border: 0;
}
#centralScrollPane {
background-color: white;
}
#footerBox {
min-height: 36;
background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:1 #99c9ff, stop:0 white);
}
#programsList QPushButton, #coursesList QPushButton, #helpList QPushButton {
background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:0 #f3f3f3, stop:1 #e0e0e0);
border-width: 1px;
border-bottom-width: 0;
border-style: solid;
font-size: 10pt;
height: 24px;
border-color: #c3c3c5;
color: #1000b0;
}
#programsList QPushButton[first="true"], #coursesList QPushButton[first="true"], #helpList QPushButton[first="true"] {
border-top-left-radius: 5;
border-top-right-radius: 5;
border-bottom-width: 0;
}
#programsList QPushButton[single="true"], #coursesList QPushButton[single="true"], #helpList QPushButton[single="true"] {
border-top-left-radius: 5;
border-top-right-radius: 5;
border-bottom-left-radius: 5;
border-bottom-right-radius: 5;
border-bottom-width: 1;
}
#programsList QPushButton[last="true"], #coursesList QPushButton[last="true"], #helpList QPushButton[last="true"] {
border-bottom-left-radius: 5;
border-bottom-right-radius: 5;
border-bottom-width: 1;
}
#programsList QPushButton:hover, #coursesList QPushButton:hover, #helpList QPushButton:hover {
color: black;
}
#programsList QPushButton:pressed, #coursesList QPushButton:pressed, #helpList QPushButton:pressed {
background-color: #f3f3f3;
}
* {
background-color: #99c9ff;
color: #115bb2;
border-width: 1;
border-bottom-width: 0;
border-style: solid;
border-color: #115bb2;
}
This diff is collapsed.
......@@ -21,9 +21,16 @@ else()
include(${QT_USE_FILE})
endif()
set(CONFIGURATION_TEMPLATE
"CourseManager,Editor,Actor*,Browser,KumirAnalizer,*CodeGenerator,KumirCodeRun,!CoreGUI"
)
if(${USE_QT} GREATER 4)
set(CONFIGURATION_TEMPLATE
"CourseManager,Editor,Actor*,KumirAnalizer,*CodeGenerator,KumirCodeRun,!CoreGUI"
)
else()
set(CONFIGURATION_TEMPLATE
"CourseManager,Editor,Actor*,Browser,KumirAnalizer,*CodeGenerator,KumirCodeRun,!CoreGUI"
)
endif()
set(SPLASHSCREEN
"coregui/splashscreens/professional.png"
......
......@@ -20,10 +20,18 @@ else()
include(${QT_USE_FILE})
endif()
set(
CONFIGURATION_TEMPLATE
"CourseManager,Editor\(teacher\),Browser,Actor*,KumirAnalizer\(teacher\),KumirCodeGenerator,KumirCodeRun,!CoreGUI\(icon=teacher\)"
)
if(${USE_QT} GREATER 4)
set(
CONFIGURATION_TEMPLATE
"CourseManager,Editor\(teacher\),Actor*,KumirAnalizer\(teacher\),KumirCodeGenerator,KumirCodeRun,!CoreGUI\(icon=teacher\)"
)
else()
set(
CONFIGURATION_TEMPLATE
"CourseManager,Editor\(teacher\),Browser,Actor*,KumirAnalizer\(teacher\),KumirCodeGenerator,KumirCodeRun,!CoreGUI\(icon=teacher\)"
)
endif()
set(
SPLASHSCREEN
"coregui/splashscreens/teacher.png"
......
......@@ -4,8 +4,12 @@ find_package(Llvm)
find_package(PythonLibs 3.2)
# Mainstream plugins to be always build
add_subdirectory(browser)
if(${USE_QT} GREATER 4)
# QtWebkit deprecated since Qt 5.5,
# so do not build Browser
else()
add_subdirectory(browser)
endif()
add_subdirectory(editor)
add_subdirectory(coregui)
add_subdirectory(coursemanager)
......
......@@ -38,6 +38,7 @@ set(SOURCES
guisettingspage.cpp
toolbarcontextmenu.cpp
iosettingseditorpage.cpp
defaultstartpage.cpp
)
set(EXTRA_LIBS
......@@ -70,6 +71,7 @@ set(MOC_HEADERS
guisettingspage.h
toolbarcontextmenu.h
iosettingseditorpage.h
defaultstartpage.h
)
set(FORMS
......@@ -79,6 +81,7 @@ set(FORMS
systemopenfilesettings.ui
guisettingspage.ui
iosettingseditorpage.ui
defaultstartpage.ui
)
set(RESOURCES
......
#include "defaultstartpage.h"
#include "plugin.h"
#include "mainwindow.h"
#include "ui_defaultstartpage.h"
#include <QtCore>
#if QT_VERSION >= 0x050000
#else
# include <QtGui>
#endif
# include <QtWidgets>
CoreGUI::DefaultStartPage::DefaultStartPage(Plugin* plugin, MainWindow* mw, QWidget *parent)
: QWidget(parent)
, _plugin(plugin)
, _mainWindow(mw)
, ui(new Ui::DefaultStartPage)
{
this->setObjectName("startPageRoot");
ui->setupUi(this);
relayoutBlocks(this->width());
ui->headerText->setText(_mainWindow->applicationTitle() + " " + _plugin->applicationVersionString());
installEventFilter(this);
createConnections();
reloadStyleSheet();
}
QString CoreGUI::DefaultStartPage::startPageTabStyle() const
{
// const QString cssFileName = _plugin->myResourcesDir().absoluteFilePath("default_startpage_tabstyle.css");
// QFile cssFile(cssFileName);
// if (cssFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
// const QString cssData = QString::fromUtf8(cssFile.readAll());
// cssFile.close();
// return cssData;
// }
// TODO uncomment after tab bar styled
return "";
}
QString CoreGUI::DefaultStartPage::startPageTitle() const
{
return windowTitle();
}
void CoreGUI::DefaultStartPage::createConnections()
{
connect(ui->btnNewProgram, SIGNAL(clicked()),
_mainWindow, SLOT(newProgram()));
connect(ui->btnLoadProgram, SIGNAL(clicked()),
_mainWindow, SLOT(fileOpen()));
connect(ui->btnShowCourses, SIGNAL(clicked()),
this, SLOT(handleShowCoursesPressed()));
connect(ui->btnShowHelp, SIGNAL(clicked()),
this, SLOT(handleShowHelpPressed()));
}
void CoreGUI::DefaultStartPage::reloadStyleSheet()
{
const QString cssFileName = _plugin->myResourcesDir().absoluteFilePath("default_startpage.css");
QFile cssFile(cssFileName);
if (cssFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
const QString cssData = QString::fromUtf8(cssFile.readAll());
cssFile.close();
setStyleSheet(cssData);
}
}
void CoreGUI::DefaultStartPage::relayoutBlocks(const int width)
{
static const int OneCol = 400;
static const int TwoCol = 780;
int columns = 3;
if (width < OneCol)
columns = 1;
else if (width < TwoCol)
columns = 2;
int programsRow, programsColumn, coursesRow, coursesColumn, helpRow, helpColumn;
if (3 == columns) {
programsRow = coursesRow = helpRow = 0;
programsColumn = 0;
coursesColumn = 1;
helpColumn = 2;
}
else if (2 == columns) {
programsRow = coursesRow = 0;
helpRow = 1;
programsColumn = 0;
coursesColumn = 1;
helpColumn = 0;
}
else if (1 == columns) {
programsColumn = coursesColumn = helpColumn = 0;
programsRow = 0;
coursesRow = 1;
helpRow = 2;
}
ui->centralViewLayout->removeWidget(ui->programsBox);
ui->centralViewLayout->removeWidget(ui->coursesBox);
ui->centralViewLayout->removeWidget(ui->headerBox);
ui->centralViewLayout->addWidget(ui->programsBox, programsRow, programsColumn, 1, 1);
ui->centralViewLayout->addWidget(ui->coursesBox, coursesRow, coursesColumn, 1, 1);
ui->centralViewLayout->addWidget(ui->helpBox, helpRow, helpColumn, 1, 1);
updateContents();
}
void CoreGUI::DefaultStartPage::updateContents()
{
updateRecentFiles();
updateRecentCourses();
updateHelp();
}
void CoreGUI::DefaultStartPage::updateRecentFiles()
{
const QStringList names = _mainWindow->recentFiles(false);
const QStringList paths = _mainWindow->recentFiles(true);
Q_FOREACH(QObject * child, ui->programsList->children()) {
QPushButton * btn = qobject_cast<QPushButton*>(child);
if (btn) {
ui->programsList->layout()->removeWidget(btn);
btn->disconnect();
btn->deleteLater();
}
}
Q_ASSERT(names.size() == paths.size());
for (int i=0; i<names.size(); ++i) {
const QString & name = names[i];
const QString & path = paths[i];
QPushButton * item = new QPushButton;
if (0 == i && 1 == names.size())
item->setProperty("single", true);
else if (0 == i)
item->setProperty("first", true);
else if (names.size()-1 == i)
item->setProperty("last", true);
QVBoxLayout * l = qobject_cast<QVBoxLayout*>(ui->programsList->layout());
l->insertWidget(l->count()-1, item);
item->setText(makeShortText(name, ui->programsList->width(), item->fontMetrics()));
item->setToolTip(path);
connect(item, SIGNAL(clicked()), this, SLOT(handleRecentFileClicked()));
}
}
void CoreGUI::DefaultStartPage::updateRecentCourses()
{
const QStringList names = _plugin->coursesList(false);
const QStringList paths = _plugin->coursesList(true);
Q_FOREACH(QObject * child, ui->coursesList->children()) {
QPushButton * btn = qobject_cast<QPushButton*>(child);
if (btn) {
ui->coursesList->layout()->removeWidget(btn);
btn->disconnect();
btn->deleteLater();
}
}
Q_ASSERT(names.size() == paths.size());
for (int i=0; i<names.size(); ++i) {
const QString & name = names[i];
const QString & path = paths[i];
QPushButton * item = new QPushButton;
if (0 == i && 1 == names.size())
item->setProperty("single", true);
else if (0 == i)
item->setProperty("first", true);
else if (names.size()-1 == i)
item->setProperty("last", true);
QVBoxLayout * l = qobject_cast<QVBoxLayout*>(ui->coursesList->layout());
l->insertWidget(l->count()-1, item);
item->setText(makeShortText(name, ui->coursesList->width(), item->fontMetrics()));
item->setToolTip(path);
connect(item, SIGNAL(clicked()), this, SLOT(handleRecentCourseClicked()));
}
}
void CoreGUI::DefaultStartPage::updateHelp()
{
const QStringList names = _plugin->helpList();
Q_FOREACH(QObject * child, ui->helpList->children()) {
QPushButton * btn = qobject_cast<QPushButton*>(child);
if (btn) {
ui->coursesList->layout()->removeWidget(btn);
btn->disconnect();
btn->deleteLater();
}
}
for (int i=0; i<names.size(); ++i) {
const QString & name = names[i];
QPushButton * item = new QPushButton;
if (0 == i && 1 == names.size())
item->setProperty("single", true);
else if (0 == i)
item->setProperty("first", true);
else if (names.size()-1 == i)
item->setProperty("last", true);
QVBoxLayout * l = qobject_cast<QVBoxLayout*>(ui->helpList->layout());
l->insertWidget(l->count()-1, item);
item->setText(makeShortText(name, ui->coursesList->width(), item->fontMetrics()));
item->setProperty("helpIndex", i);
connect(item, SIGNAL(clicked()), this, SLOT(handleHelpItemClicked()));
}
}
QString CoreGUI::DefaultStartPage::makeShortText(const QString &s, const int maxWidth, const QFontMetrics & fm)
{
static const int Margins = 30;
const int availableWidth = maxWidth - Margins;
QString ss = s;
int w = fm.width(ss);
if (w <= availableWidth) {
return ss;
}
while (ss.length() > 0) {
ss.remove(ss.length()-1, 1);
w = fm.width(ss + "...");
if (w <= availableWidth) {
break;
}
}
return ss + "...";
}
bool CoreGUI::DefaultStartPage::eventFilter(QObject *obj, QEvent *evt)
{
if (obj == this && QEvent::MouseButtonPress == evt->type()) {
QMouseEvent * event = static_cast<QMouseEvent*>(evt);
if (Qt::RightButton == event->button()) {
#ifndef QT_NO_DEBUG
reloadStyleSheet();
qDebug() << "Reload style sheet";
#endif
}
}
else if (obj == this && QEvent::Resize == evt->type()) {
QResizeEvent * event = static_cast<QResizeEvent*>(evt);
relayoutBlocks(event->size().width());
}
else if (obj == this && QEvent::Show == evt->type()) {
updateContents();
}
return false;
}
void CoreGUI::DefaultStartPage::handleShowCoursesPressed()
{
_plugin->showCoursesWindow(QString());
}
void CoreGUI::DefaultStartPage::handleShowHelpPressed()
{
_plugin->showHelpWindow(-1);
}
void CoreGUI::DefaultStartPage::handleRecentFileClicked()
{
QPushButton * btn = qobject_cast<QPushButton*>(sender());
if (!btn) return;
const QString & path = btn->toolTip();
_mainWindow->loadRecentFile(path);
}
void CoreGUI::DefaultStartPage::handleRecentCourseClicked()
{
QPushButton * btn = qobject_cast<QPushButton*>(sender());
if (!btn) return;
const QString & path = btn->toolTip();
_plugin->showCoursesWindow(path);
}
void CoreGUI::DefaultStartPage::handleHelpItemClicked()
{
QPushButton * btn = qobject_cast<QPushButton*>(sender());
if (!btn) return;
const int index = btn->property("helpIndex").toInt();
_plugin->showHelpWindow(index);
}
#ifndef DEFAULT_START_PAGE_H
#define DEFAULT_START_PAGE_H
#include "interfaces/startpage_widget_interface.h"
#include <QtCore>
#if QT_VERSION >= 0x050000
#else
# include <QtGui>
#endif
# include <QtWidgets>
namespace CoreGUI {
namespace Ui {
class DefaultStartPage;
}
class Plugin;
class MainWindow;
class DefaultStartPage
: public QWidget
, public Shared::StartpageWidgetInterface
{
Q_OBJECT
Q_INTERFACES(Shared::StartpageWidgetInterface)
public:
explicit DefaultStartPage(Plugin* plugin, MainWindow * mw, QWidget * parent = 0);
QString startPageTabStyle() const;
protected /*methods*/:
void createConnections();
void reloadStyleSheet();
void relayoutBlocks(const int width);
void updateContents();
void updateRecentFiles();
void updateRecentCourses();
void updateHelp();
QString makeShortText(const QString &s, const int maxWidth, const QFontMetrics & fm);
bool eventFilter(QObject *obj, QEvent *evt);
protected Q_SLOTS:
void handleShowCoursesPressed();
void handleShowHelpPressed();
void handleRecentFileClicked();
void handleRecentCourseClicked();
void handleHelpItemClicked();
protected /*fields*/:
Plugin* _plugin;
MainWindow* _mainWindow;
Ui::DefaultStartPage * ui;
// StartpageWidgetInterface interface
public:
inline QWidget *startPageWidget() { return this; }
QString startPageTitle() const;
inline void setStartPageTitleChangeHandler(const QObject *, const char *) {}
};
}
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CoreGUI::DefaultStartPage</class>
<widget class="QWidget" name="CoreGUI::DefaultStartPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>551</width>
<height>344</height>
</rect>
</property>
<property name="windowTitle">
<string>Start</string>
</property>