Skip to content

Commit

Permalink
Merge pull request #399 from guitorri/searchboxes-fix-crash
Browse files Browse the repository at this point in the history
qucslib: Searchboxes fix crash
  • Loading branch information
guitorri committed Jan 25, 2016
2 parents 8f9834d + 1e740ac commit 67ccb23
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 48 deletions.
10 changes: 6 additions & 4 deletions qucs/qucs-lib/qucslib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ QucsLib::QucsLib()

QAction * manageLib =new QAction (tr("Manage User &Libraries..."), this);
manageLib->setShortcut(Qt::CTRL+Qt::Key_M);
connect(manageLib, SIGNAL(activated()), SLOT(slotManageLib()));
connect(manageLib, SIGNAL(triggered()), SLOT(slotManageLib()));

QAction * fileQuit = new QAction(tr("&Quit"), this);
fileQuit->setShortcut(Qt::CTRL+Qt::Key_Q);
connect(fileQuit, SIGNAL(activated()), SLOT(slotQuit()));
connect(fileQuit, SIGNAL(triggered()), SLOT(slotQuit()));

fileMenu->addAction(manageLib);
fileMenu->addSeparator();
Expand All @@ -78,11 +78,11 @@ QucsLib::QucsLib()
QAction * helpHelp = new QAction(tr("&Help"), this);
helpHelp->setShortcut(Qt::Key_F1);
helpMenu->addAction(helpHelp);
connect(helpHelp, SIGNAL(activated()), SLOT(slotHelp()));
connect(helpHelp, SIGNAL(triggered()), SLOT(slotHelp()));

QAction * helpAbout = new QAction(tr("About"), this);
helpMenu->addAction(helpAbout);
connect(helpAbout, SIGNAL(activated()), SLOT(slotAbout()));
connect(helpAbout, SIGNAL(triggered()), SLOT(slotAbout()));

// use Escape key to clear search
QAction *escape = new QAction(this);
Expand Down Expand Up @@ -233,6 +233,7 @@ void QucsLib::slotQuit()
tmp = y(); // ... set them correctly before closing the ...
tmp = width(); // dialog !!! Otherwise the frame of the window ...
tmp = height(); // will not be recognized (a X11 problem).
Q_UNUSED(tmp);

qApp->quit();
}
Expand All @@ -245,6 +246,7 @@ void QucsLib::closeEvent(QCloseEvent *Event)
tmp = y(); // ... set them correctly before closing the ...
tmp = width(); // dialog !!! Otherwise the frame of the window ...
tmp = height(); // will not be recognized (a X11 problem).
Q_UNUSED(tmp);

Event->accept();
}
Expand Down
19 changes: 19 additions & 0 deletions qucs/qucs-lib/symbolwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ SymbolWidget::SymbolWidget(QWidget *parent) : QWidget(parent)
{

Text_x = Text_y = 0;
cx = 0;
cy = 0;
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
PaintText = tr("Symbol:");
QFontMetrics metrics(QucsSettings.font, 0); // use the the screen-compatible metric
TextWidth = metrics.width(PaintText) + 4; // get size of text
Expand Down Expand Up @@ -99,6 +105,9 @@ void SymbolWidget::paintEvent(QPaintEvent*)
QPainter Painter(this);
Painter.drawText(2, 2, 0, 0, Qt::AlignLeft | Qt::TextDontClip, PaintText);

QFontMetrics metrics(QucsSettings.font, 0);
Painter.drawText(2, metrics.height(), 0, 0, Qt::AlignLeft | Qt::TextDontClip, Warning);

int dx = (x2-x1)/2 + TextWidth - DragNDropWidth/2;
if(dx < 2) dx = 2;
Painter.drawText(dx, y2-y1+2, 0, 0, Qt::AlignLeft | Qt::TextDontClip, DragNDropText);
Expand Down Expand Up @@ -162,6 +171,8 @@ int SymbolWidget::createSymbol(const QString& Lib_, const QString& Comp_)
LibraryName = Lib_;
ComponentName = Comp_;

Warning.clear();

int PortNo = 0;
QString Comp = ModelString.section(' ', 0,0);
Comp.remove(0, 1); // remove '<'
Expand Down Expand Up @@ -285,6 +296,7 @@ int SymbolWidget::createSymbol(const QString& Lib_, const QString& Comp_)
else if(Comp == "hicumL2V2p1" || Comp == "hic2_full" ||
Comp == "hic0_full" || Comp == "hicumL0V1p2" ||
Comp == "hicumL2V2p23" || Comp == "hicumL2V2p24" ||
Comp == "hicumL2V2p31n" ||
Comp == "hicumL0V1p2g" || Comp == "hicumL0V1p3") {
// normal bipolar
Lines.append(new Line(-10,-15,-10, 15,QPen(Qt::darkBlue,3)));
Expand Down Expand Up @@ -378,6 +390,13 @@ int SymbolWidget::createSymbol(const QString& Lib_, const QString& Comp_)
x1 = -34; y1 =-44;
x2 = 84; y2 = 20;
}
else {
// Warn in case a default component symbol is not
// mapped or implemented.
Warning = tr("Warning: Symbol '%1' missing in Qucs Library.\n"
"Drag and Drop may still work.\n"
"Please contact the developers.").arg(Comp);
}

x1 -= 4; // enlarge component boundings a little
x2 += 4;
Expand Down
47 changes: 3 additions & 44 deletions qucs/qucs-lib/symbolwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,6 @@
class QPaintEvent;
class QSizePolicy;


//struct Line {
// Line(int _x1, int _y1, int _x2, int _y2, QPen _style)
// : x1(_x1), y1(_y1), x2(_x2), y2(_y2), style(_style) {};
// int x1, y1, x2, y2;
// QPen style;
//};
//
//struct Arc {
// Arc(int _x, int _y, int _w, int _h, int _angle, int _arclen, QPen _style)
// : x(_x), y(_y), w(_w), h(_h), angle(_angle),
// arclen(_arclen), style(_style) {};
// int x, y, w, h, angle, arclen;
// QPen style;
//};
//
//struct Area {
// Area(int _x, int _y, int _w, int _h, QPen _Pen,
// QBrush _Brush = QBrush(Qt::NoBrush))
// : x(_x), y(_y), w(_w), h(_h), Pen(_Pen), Brush(_Brush) {};
// int x, y, w, h;
// QPen Pen;
// QBrush Brush; // filling style/color
//};
//
//struct Text {
// Text(int _x, int _y, const QString& _s, QColor _Color = QColor(0,0,0),
// float _Size = 10.0, float _mCos=1.0, float _mSin=0.0)
// : x(_x), y(_y), s(_s), Color(_Color), Size(_Size) {};
// int x, y;
// QString s;
// QColor Color;
// float Size;
//};



class SymbolWidget : public QWidget {
Q_OBJECT
public:
Expand All @@ -101,19 +64,15 @@ class SymbolWidget : public QWidget {
bool getPen (const QString&, QPen&, int);
bool getBrush(const QString&, QBrush&, int);

//Q3DragObject *myDragObject;

QString PaintText, DragNDropText;
QString PaintText;
QString DragNDropText;
QString Warning;
int TextWidth, DragNDropWidth, TextHeight;
int cx, cy, x1, x2, y1, y2;
QList<Line *> Lines;
QList<Arc *> Arcs;
QList<Area *> Rects, Ellips;
QList<Text *> Texts;
//Q3PtrList<Line> Lines;
//Q3PtrList<struct Arc> Arcs;
//Q3PtrList<Area> Rects, Ellips;
//Q3PtrList<Text> Texts;
};

#endif // SYMBOLWIDGET_H

0 comments on commit 67ccb23

Please sign in to comment.