add a simple frame component used in examples

This commit is contained in:
laserpants 2016-03-19 16:28:38 +03:00
parent e1a44b78db
commit 4621d08cdc
10 changed files with 83 additions and 0 deletions

0
examples/about.cpp Normal file
View File

4
examples/about.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef ABOUT_H
#define ABOUT_H
#endif // ABOUT_H

0
examples/examplelist.cpp Normal file
View File

4
examples/examplelist.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef EXAMPLELIST_H
#define EXAMPLELIST_H
#endif // EXAMPLELIST_H

0
examples/exampleview.cpp Normal file
View File

4
examples/exampleview.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef EXAMPLEVIEW_H
#define EXAMPLEVIEW_H
#endif // EXAMPLEVIEW_H

View File

View File

@ -0,0 +1,4 @@
#ifndef FLATBUTTONEXAMPLES_H
#define FLATBUTTONEXAMPLES_H
#endif // FLATBUTTONEXAMPLES_H

42
examples/frame.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <QHBoxLayout>
#include <QTextEdit>
#include <QLabel>
#include "frame.h"
Frame::Frame(QWidget *parent)
: QWidget(parent),
_edit(new QTextEdit),
_layout(new QHBoxLayout)
{
setLayout(_layout);
_layout->addWidget(new QLabel("placeholder"));
QFont font("monospace");
font.setPixelSize(12);
_edit->setTextInteractionFlags(Qt::TextBrowserInteraction);
_edit->setFont(font);
_layout->addWidget(_edit);
_layout->setStretch(0, 1);
_layout->setStretch(1, 1);
setMinimumHeight(300);
}
Frame::~Frame()
{
}
void Frame::setCodeSnippet(const QString &snippet)
{
_edit->setText(snippet);
}
void Frame::setWidget(QWidget *widget)
{
QWidget *old = _layout->itemAt(0)->widget();
_layout->replaceWidget(old, widget);
old->deleteLater();
}

25
examples/frame.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef FRAME_H
#define FRAME_H
#include <QWidget>
class QTextEdit;
class QHBoxLayout;
class Frame : public QWidget
{
Q_OBJECT
public:
explicit Frame(QWidget *parent = 0);
~Frame();
void setCodeSnippet(const QString &snippet);
void setWidget(QWidget *widget);
private:
QTextEdit *const _edit;
QHBoxLayout *const _layout;
};
#endif // FRAME_H