File: algoeditorview.cpp

package info (click to toggle)
algobox 1.0.3+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,380 kB
  • sloc: cpp: 13,758; makefile: 13; xml: 8; sh: 5
file content (114 lines) | stat: -rw-r--r-- 3,601 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/***************************************************************************
 *   copyright       : (C) 2009-2019 by Pascal Brachet                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "algoeditorview.h"
#include <QVBoxLayout>
#include <QFrame>
#include <QTextDocument>
#include <QTextCursor>
#include <QTextEdit>
#include <QLineEdit>
#include <QTextBlock>
#include <QFontDatabase>

AlgoEditorView::AlgoEditorView(QWidget *parent) : QWidget(parent)
{
QFontDatabase fdb;
QStringList xf = fdb.families();
QString deft;
if (xf.contains("Liberation Mono",Qt::CaseInsensitive)) deft="Liberation Mono";
else if (xf.contains("DejaVu Sans Mono",Qt::CaseInsensitive)) deft="DejaVu Sans Mono";
#if defined(Q_OS_MAC)
else if (xf.contains("Courier",Qt::CaseInsensitive)) deft="Courier";
#endif
#if defined(Q_OS_WIN32)
else if (xf.contains("Courier New",Qt::CaseInsensitive)) deft="Courier New";
#endif
else deft=qApp->font().family();  
efont.setFamily(deft);
//efont.setPointSize(qApp->font().pointSize());
//QFont efont(deft,qApp->font().pointSize());

QVBoxLayout* mainlay = new QVBoxLayout( this );
mainlay->setSpacing(0);
mainlay->setMargin(0);

QFrame *frame=new QFrame(this);
frame->setLineWidth(1);
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Sunken);
mainlay->addWidget(frame);

editor=new AlgoEditor(frame,efont);
connect(editor, SIGNAL(dofind()), this, SLOT(editFind()));
connect(editor, SIGNAL(doreplace()), this, SLOT(editReplace()));

m_lineNumberWidget = new LineNumberWidget( editor, frame);
// m_lineNumberWidget->setFont(efont);
// QFontMetrics fm( efont );
// m_lineNumberWidget->setFixedWidth( fm.width( "00000" ) + 14 );
QHBoxLayout* lay = new QHBoxLayout( frame );
lay->setSpacing(0);
lay->setMargin(0);
lay->addWidget( m_lineNumberWidget );
lay->addWidget( editor );
setFocusProxy( editor );
setLineNumberWidgetVisible(true);

findwidget=new FindWidget(this);
mainlay->addWidget(findwidget);
findwidget->SetEditor(editor);
findwidget->hide();
}

AlgoEditorView::~AlgoEditorView()
{
}

void AlgoEditorView::setLineNumberWidgetVisible( bool b )
{
    if( b ){
	m_lineNumberWidget->show();
    } else {
	m_lineNumberWidget->hide();
    }
}

void AlgoEditorView::editFind()
{
QTextCursor c =editor->textCursor();
if (c.hasSelection()) findwidget->ui.comboFind->lineEdit()->setText(c.selectedText());
findwidget->show();
findwidget->ui.comboFind->setFocus();
findwidget->ui.comboFind->lineEdit()->selectAll();
}

void AlgoEditorView::editReplace()
{
if ( !replaceDialog )  replaceDialog = new ReplaceDialog(this, 0);
replaceDialog->SetEditor(editor);
QTextCursor c =editor->textCursor();
if (c.hasSelection()) replaceDialog->ui.comboFind->lineEdit()->setText(c.selectedText());
replaceDialog->show();
replaceDialog->raise();
replaceDialog->ui.comboFind->setFocus();
replaceDialog->ui.comboFind->lineEdit()->selectAll();
}

void AlgoEditorView::setFontSize(int size)
{
efont.setPointSize(size);
m_lineNumberWidget->setFont(efont);
QFontMetrics fm( efont );
m_lineNumberWidget->setFixedWidth( fm.width( "00000" ) + 14 );
editor->setFont(efont);
}