Skip to content

Commit

Permalink
- Fix the documentation text clipping.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10266 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 1, 2011
1 parent 7674c2e commit 6ac155e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
56 changes: 41 additions & 15 deletions OMEdit/OMEditGUI/DocumentationWidget.cpp
Expand Up @@ -33,6 +33,11 @@

#include "DocumentationWidget.h"

//! @class DocumentationWidget
//! @brief Displays the model documentation.

//! Constructor
//! @param pParent is the pointer to MainWindow.
DocumentationWidget::DocumentationWidget(MainWindow *pParent)
: QWidget(pParent)
{
Expand Down Expand Up @@ -60,25 +65,29 @@ DocumentationWidget::DocumentationWidget(MainWindow *pParent)
mpSaveButton->setMaximumSize(QSize(100,20));
connect(mpSaveButton, SIGNAL(clicked()), SLOT(saveChanges()));
QHBoxLayout *horizontalLayout = new QHBoxLayout;
horizontalLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
horizontalLayout->addWidget(mpPixmapLabel);
horizontalLayout->addWidget(mpHeadingLabel);
horizontalLayout->addWidget(mpSaveButton);
horizontalLayout->addWidget(mpEditButton);

// set layout
QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
verticalLayout->addLayout(horizontalLayout);
verticalLayout->addWidget(mpDocumentationViewer);
verticalLayout->addWidget(mpDocumentationEditor);

setLayout(verticalLayout);
}

//! Destructor
DocumentationWidget::~DocumentationWidget()
{
delete mpDocumentationViewer;
delete mpDocumentationEditor;
}

//! Shows the documentation of a model
//! @param className the model name
void DocumentationWidget::show(QString className)
{
mClassName=className;
Expand Down Expand Up @@ -113,6 +122,8 @@ void DocumentationWidget::show(QString className)
mpDocumentationEditor->setVisible(false);
}

//! Shows the documenation editing view.
//! @param className the model name
void DocumentationWidget::showDocumentationEditView(QString className)
{
mpDocumentationViewer->hide();
Expand All @@ -126,11 +137,15 @@ void DocumentationWidget::showDocumentationEditView(QString className)
mpDocumentationEditor->show();
}

//! Sets the model as custom model.
//! @param isCustomModel
void DocumentationWidget::setIsCustomModel(bool isCustomModel)
{
mIsCustomModel = isCustomModel;
}

//! Returns true if the model is a custom model.
//! @return bool true if model is a custom model
bool DocumentationWidget::isCustomModel()
{
return mIsCustomModel;
Expand All @@ -143,6 +158,7 @@ void DocumentationWidget::editDocumentation()
mpSaveButton->setDisabled(false);
}

//! Save the changes made to the documentation of the model.
void DocumentationWidget::saveChanges()
{
QString doc = mpDocumentationEditor->toPlainText();
Expand All @@ -159,18 +175,11 @@ void DocumentationWidget::saveChanges()
}
}

void DocumentationWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter (this);
painter.setPen(Qt::gray);
QRect rectangle = this->rect();
rectangle.setWidth(this->rect().width() - 2);
rectangle.setHeight(this->rect().height() - 2);
painter.drawRect(rectangle);
QWidget::paintEvent(event);
}
//! @class DocumentationEditor
//! @brief An editor for editing the documentation of the model.

//! Constructor
//! @param pParent is the pointer to DocumentationWidget.
DocumentationEditor::DocumentationEditor(DocumentationWidget *pParent)
: QTextEdit(pParent)
{
Expand All @@ -185,6 +194,11 @@ DocumentationEditor::DocumentationEditor(DocumentationWidget *pParent)
this->setFontPointSize(10.0);
}

//! @class DocumentationViewer
//! @brief A webview for displaying the html documentation.

//! Constructor
//! @param pParent is the pointer to DocumentationWidget.
DocumentationViewer::DocumentationViewer(DocumentationWidget *pParent)
: QWebView(pParent)
{
Expand All @@ -197,25 +211,31 @@ DocumentationViewer::DocumentationViewer(DocumentationWidget *pParent)
QString baseUrl = QString(Helper::OpenModelicaLibrary).replace("\\", "/").append("/Modelica ").append(versionStr).append("/Images/");
setBaseUrl(baseUrl);
// set page font settings
settings()->setFontFamily(QWebSettings::StandardFont, "Verdana");
settings()->setFontSize(QWebSettings::DefaultFontSize, 10);
//settings()->setFontFamily(QWebSettings::StandardFont, "Verdana");
//settings()->setFontSize(QWebSettings::DefaultFontSize, 10);
// set page links settings
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);

connect(this, SIGNAL(linkClicked(QUrl)), SLOT(processLinkClick(QUrl)));
connect(this->page(), SIGNAL(linkHovered(QString,QString,QString)), SLOT(processLinkHover(QString,QString,QString)));
}

//! Sets a base url for the webview.
//! @param url the base url
void DocumentationViewer::setBaseUrl(QString url)
{
mBaseUrl.setUrl(url);
}

//! Returns the base url.
//! @return QUrl the base url.
QUrl DocumentationViewer::getBaseUrl()
{
return mBaseUrl;
}

//! Slot activated when linkClicked signal of webview is raised.
//! Handles the link processing. Sends all the http starting links to the QDesktopServices and process all Modelica starting links.
void DocumentationViewer::processLinkClick(QUrl url)
{
//! @todo
Expand Down Expand Up @@ -247,6 +267,8 @@ void DocumentationViewer::processLinkClick(QUrl url)
}
}

//! Slot activated when QNetworkReply finished signal is raised.
//! Handles the link redirected to https.
void DocumentationViewer::requestFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(const_cast<QObject*>(sender()));
Expand All @@ -261,6 +283,8 @@ void DocumentationViewer::requestFinished()
reply->deleteLater();
}

//! Slot activated when linkHovered signal of web view is raised.
//! Writes the url to the status bar.
void DocumentationViewer::processLinkHover(QString link, QString title, QString textContent)
{
Q_UNUSED(title);
Expand All @@ -272,6 +296,8 @@ void DocumentationViewer::processLinkHover(QString link, QString title, QString
mpParentDocumentationWidget->mpParentMainWindow->mpStatusBar->showMessage(link);
}

//! Reimplementation of mousePressEvent.
//! Disables the webview rightclick.
void DocumentationViewer::mousePressEvent(QMouseEvent *event)
{
// dont allow right click on Documentation Viewer
Expand Down
2 changes: 0 additions & 2 deletions OMEdit/OMEditGUI/DocumentationWidget.h
Expand Up @@ -67,8 +67,6 @@ public slots:
QPushButton *mpSaveButton;
QDialogButtonBox *mpButtonBox;
QString mClassName;
protected:
virtual void paintEvent(QPaintEvent *event);
};
class ModelicaTextSettings;

Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/mainwindow.cpp
Expand Up @@ -143,7 +143,9 @@ MainWindow::MainWindow(SplashScreen *splashScreen, QWidget *parent)
documentationdock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
documentationdock->setContentsMargins(0, 1, 1, 1);
mpDocumentationWidget = new DocumentationWidget(this);
documentationdock->setWidget(mpDocumentationWidget);
QScrollArea *documentationScrollArea = new QScrollArea;
documentationScrollArea->setWidget(mpDocumentationWidget);
documentationdock->setWidget(documentationScrollArea);
addDockWidget(Qt::RightDockWidgetArea, documentationdock);
documentationdock->hide();
//Create Actions, Toolbar and Menus
Expand Down

0 comments on commit 6ac155e

Please sign in to comment.