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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
|
/***************************************************************************
* Copyright (C) 2008 by Alexey Balakin *
* mathgl.abalakin@gmail.com *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QTime>
#include <QMenu>
#include <QPrinter>
#include <QTimer>
#include <QElapsedTimer>
#include <QScrollArea>
#include <QPainter>
#include <QPrintDialog>
#include <QToolButton>
#include <QToolBar>
#include <QSpinBox>
#include <QBoxLayout>
#include <QMenuBar>
#include <QMessageBox>
#include <QTextEdit>
#include <QTextBlock>
#include <QMdiArea>
#include "udav_wnd.h"
#include "mgl2/qmathgl.h"
#include "plot_pnl.h"
#include "anim_dlg.h"
#include "style_dlg.h"
#include "newcmd_dlg.h"
#include "subplot_dlg.h"
#undef sprintf
extern bool mglAutoSave;
extern bool mglHighlight;
extern bool mglDotsRefr;
extern mglParse parser;
int animDelay=500;
void raisePanel(QWidget *w);
//-----------------------------------------------------------------------------
PlotPanel::PlotPanel(QWidget *parent) : QWidget(parent)
{
gifOn = jpgOn = false;
animDialog = new AnimParam(this); animPos = -1;
stlDialog = new StyleDialog(this);
newCmdDlg = new NewCmdDialog(this);
subplotDlg = new SubplotDialog(this);
printer = new QPrinter; curPos = subId = -1;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(next()));
connect(animDialog, SIGNAL(putText(const QString &)), this, SLOT(animText(const QString &)));
connect(newCmdDlg, SIGNAL(result(const QString&, bool)), this, SLOT(putCmd(const QString&)));
connect(subplotDlg, SIGNAL(result(const QString&)), this, SLOT(insCmd(const QString&)));
menu = new QMenu(_("Graphics"),this);
popup = new QMenu(this);
mgl = new QMathGL(this);
draw = new mglDrawScript(parser.Self());
mgl_set_flag(mgl->getGraph(),1,MGL_SHOW_POS); mgl->setDraw(draw);
connect(mgl,SIGNAL(askStyle(int)),this,SLOT(setStyle(int)));
connect(mgl,SIGNAL(objChanged(int)),this,SLOT(setCurPos(int)));
QBoxLayout *v = new QVBoxLayout(this); toolTop(v);
QBoxLayout *h = new QHBoxLayout(); v->addLayout(h); toolLeft(h);
mgl->setPopup(popup);
sv = new QScrollArea(this); h->addWidget(sv); sv->setWidget(mgl);
emit giveFocus();
}
//-----------------------------------------------------------------------------
PlotPanel::~PlotPanel() { delete printer; }
//-----------------------------------------------------------------------------
void PlotPanel::setStyle(int id)
{ if(stlDialog->exec()) mgl->setStyle(id, stlDialog->getStyle()); }
//-----------------------------------------------------------------------------
void PlotPanel::setSubId(int id) { subId = id; }
//-----------------------------------------------------------------------------
void PlotPanel::animText(const QString &txt) { animPutText(txt); }
//-----------------------------------------------------------------------------
void PlotPanel::setCurPos(int pos)
{
if(!mglHighlight) pos = -1;
if(curPos!=pos) { curPos = pos; execute(); }
}
//-----------------------------------------------------------------------------
void PlotPanel::stop() { parser.Stop(); mgl->stop(); }
//-----------------------------------------------------------------------------
void PlotPanel::execute()
{
if(mglAutoSave) save();
mgl->setDotsPreview(mglDotsRefr);
raisePanel(this);
objId = subId = -1;
emit clearWarn();
QElapsedTimer t; t.start();
mgl_set_facenum(mgl->getGraph(),0);
draw->text=textMGL->toPlainText();
draw->line=curPos;
mgl->update();
setStatus(QString(_("Drawing time %1 ms")).arg(t.elapsed()*1e-3));
emit giveFocus();
}
//-----------------------------------------------------------------------------
void PlotPanel::pressF9()
{
int l=animParam.length(), i;
wchar_t *str = new wchar_t[l+2];
animPos = 0; curPos = -1;
QString cur = animParam.section('\n',animPos,animPos);
for(i=0;i<l;i++) str[i] = (cur[i]).unicode();
str[i] = 0;
parser.AddParam(0,str);
delete []str;
QElapsedTimer t; t.start();
parser.RestoreOnce();
draw->text=textMGL->toPlainText();
draw->line=curPos; mgl->update();
setStatus(QString(_("Drawing time %1 ms")).arg(t.elapsed()*1e-3));
emit giveFocus();
}
//-----------------------------------------------------------------------------
void PlotPanel::animStart(bool st)
{
if(!st)
{ timer->stop(); if(gifOn) mgl_close_gif(mgl->getGraph()); return; }
if(animParam.isEmpty())
{
if(animDialog->exec())
{
animParam = animDialog->getResult();
gifOn = animDialog->gifOn;
jpgOn = animDialog->jpgOn;
}
else return;
}
timer->start(animDelay);
if(gifOn)
{
mglGraph gr(mgl->getGraph());
gr.StartGIF("", animDelay);
gr.ResetFrames();
}
raisePanel(this);
}
//-----------------------------------------------------------------------------
void PlotPanel::nextSlide()
{
animSwitch(false);
next();
emit giveFocus();
}
//-----------------------------------------------------------------------------
void PlotPanel::next()
{
if(animParam.isEmpty())
{
if(animDialog->exec())
{
animParam = animDialog->getResult();
gifOn = animDialog->gifOn;
jpgOn = animDialog->jpgOn;
}
else return;
}
int l=animParam.length(), n=animParam.count('\n') + (animParam[l-1]=='\n' ? 0:1), i;
wchar_t *str = new wchar_t[l+2];
animPos = (animPos+1)%n;
QString cur = animParam.section('\n',animPos,animPos);
for(i=0;i<l;i++) str[i] = (cur[i]).unicode();
str[i] = 0;
parser.AddParam(0,str);
delete []str;
mglGraph gr(mgl->getGraph());
if(gr.GetNumFrame() >= n) execute();
else
{
gr.NewFrame(); execute(); gr.EndFrame();
if(jpgOn) gr.WriteFrame();
QString s; s=QString(_("%1 - %2 of %3")).arg(gr.GetNumFrame()).arg(animPos).arg(n);
setStatus(QString(_("Frame %1 of %2")).arg(animPos).arg(n));
}
}
//-----------------------------------------------------------------------------
void PlotPanel::prevSlide()
{
if(animParam.isEmpty())
{
if(animDialog->exec())
{
animParam = animDialog->getResult();
gifOn = animDialog->gifOn;
jpgOn = animDialog->jpgOn;
}
else return;
}
animSwitch(false);
int l=animParam.length(), n=animParam.count('\n') + (animParam[l-1]=='\n' ? 0:1), i;
wchar_t *str = new wchar_t[l+2];
animPos = (animPos-1+n)%n;
QString cur = animParam.section('\n',animPos,animPos);
for(i=0;i<l;i++) str[i] = (cur[i]).unicode();
str[i] = 0;
parser.AddParam(0,str);
delete []str;
execute();
emit giveFocus();
}
//-----------------------------------------------------------------------------
void PlotPanel::animSetup()
{
if(animDialog->exec())
{
animParam = animDialog->getResult();
gifOn = animDialog->gifOn;
jpgOn = animDialog->jpgOn;
animPos = -1;
}
}
//-----------------------------------------------------------------------------
void PlotPanel::adjust()
{
mgl->setSize(sv->width()-5, sv->height()-5);
raisePanel(this); emit giveFocus();
}
//-----------------------------------------------------------------------------
void PlotPanel::setMGLFont(const QString &path) { mgl->setMGLFont(path); }
//-----------------------------------------------------------------------------
void PlotPanel::animParseText(const QString &txt)
{
int i, n = txt.count('\n')+1;
double a1=0,a2=0,da=0;
QString s, all;
for(i=0;i<n;i++)
{
s = txt.section('\n',i,i);
if(s[0]=='#' && s[1]=='#' && s[2]=='a' && s[3].isSpace())
all = all + s.mid(4) + "\n";
if(s[0]=='#' && s[1]=='#' && s[2]=='c' && s[3].isSpace())
{
s = s.mid(4);
a1 = s.section(' ',0,0).toDouble();
a2 = s.section(' ',1,1).toDouble();
da = s.section(' ',2,2).toDouble();
animDialog->setResult(a1,a2,da);
}
}
if(!all.isEmpty())
{
animDialog->setResult(all);
animParam = all;
}
else if(a1!=a2 && da!=0)
{
for(double a=a1;a<=a2;a+=da) all = all + QString::number(a)+"\n";
animParam = all;
}
}
//-----------------------------------------------------------------------------
//#include "xpm/wire.xpm"
#include "xpm/text.xpm"
#include "xpm/line.xpm"
#include "xpm/curve.xpm"
#include "xpm/mark_o.xpm"
#include "xpm/mark_s.xpm"
#include "xpm/mark_a.xpm"
#include "xpm/mark_d.xpm"
#include "xpm/arc.xpm"
#include "xpm/polygon.xpm"
#include "xpm/box.xpm"
//-----------------------------------------------------------------------------
void PlotPanel::toolTop(QBoxLayout *v)
{
QAction *a, *aa;
QMenu *o=menu, *oo;
QToolBar *t = new QToolBar(this); v->addWidget(t); t->setMovable(false);
// graphics menu
a = new QAction(QPixmap(":/png/alpha.png"), _("Alpha"), this);
a->setShortcut(Qt::CTRL|Qt::Key_T); a->setCheckable(true);
connect(a, SIGNAL(toggled(bool)), mgl, SLOT(setAlpha(bool)));
connect(mgl, SIGNAL(alphaChanged(bool)), a, SLOT(setChecked(bool)));
a->setToolTip(_("Switch on/off transparency for the graphics (Ctrl+T)."));
o->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/weather-clear.png"), _("Light"), this);
a->setShortcut(Qt::CTRL|Qt::Key_L); a->setCheckable(true);
connect(a, SIGNAL(toggled(bool)), mgl, SLOT(setLight(bool)));
connect(mgl, SIGNAL(lightChanged(bool)), a, SLOT(setChecked(bool)));
a->setToolTip(_("Switch on/off lightning for the graphics (Ctrl+L)."));
o->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/view-grid.png"), _("Grid"), this);
a->setShortcut(Qt::CTRL|Qt::Key_G); a->setCheckable(true);
connect(a, SIGNAL(toggled(bool)), mgl, SLOT(setGrid(bool)));
a->setToolTip(_("Switch on/off grid of absolute coordinates (Ctrl+G)."));
o->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/transform-move.png"), _("Rotate by mouse"), this);
a->setCheckable(true);
connect(a, SIGNAL(toggled(bool)), mgl, SLOT(setRotate(bool)));
connect(mgl, SIGNAL(rotateChanged(bool)), a, SLOT(setChecked(bool)));
a->setToolTip(_("Switch on/off mouse handling of the graphics\n(rotation, shifting, zooming and perspective)."));
t->addAction(a);
/* a = new QAction(QPixmap(":/png/zoom-fit-best.png"), _("Zoom by mouse"), this);
a->setCheckable(true);
connect(a, SIGNAL(toggled(bool)), mgl, SLOT(setZoom(bool)));
connect(mgl, SIGNAL(zoomChanged(bool)), a, SLOT(setChecked(bool)));
a->setToolTip(_("Switch on/off mouse zoom of selected region."));
t->addAction(a);*/
o->addSeparator();
a = new QAction(QPixmap(":/png/zoom-original.png"), _("Restore"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(restore()));
a->setToolTip(_("Restore default graphics rotation, zoom and perspective (Ctrl+Space)."));
a->setShortcut(Qt::CTRL|Qt::Key_Space);
o->addAction(a); popup->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/view-refresh.png"), _("Redraw"), this);
connect(a, SIGNAL(triggered()), this, SLOT(execute()));
a->setToolTip(_("Execute script and redraw graphics (F5)."));
a->setShortcut(Qt::Key_F5);
o->addAction(a); popup->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/view-fullscreen.png"), _("Adjust size"), this);
connect(a, SIGNAL(triggered()), this, SLOT(adjust()));
a->setToolTip(_("Change canvas size to fill whole region (F6)."));
a->setShortcut(Qt::Key_F6); o->addAction(a);
a = new QAction(QPixmap(":/png/document-revert.png"), _("Reload"), this);
connect(a, SIGNAL(triggered()), this, SLOT(pressF9()));
a->setToolTip(_("Restore status for 'once' command and reload data (F9)."));
a->setShortcut(Qt::Key_F9); o->addAction(a); popup->addAction(a);
a = new QAction(QPixmap(":/png/process-stop.png"), _("Stop"), this);
connect(a, SIGNAL(triggered()), this, SLOT(stop()));
a->setToolTip(_("Stop script execution (F7)."));
a->setShortcut(Qt::Key_F7); o->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/edit-copy.png"), _("Copy plot"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(copy()));
a->setToolTip(_("Copy graphics to clipboard (Ctrl+Shift+G)."));
a->setShortcut(Qt::CTRL|Qt::SHIFT|Qt::Key_G);
o->addAction(a); popup->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/edit-copy.png"), _("Copy click coor."), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(copyClickCoor()));
a->setToolTip(_("Copy coordinates of last mouse click to clipboard."));
o->addAction(a); popup->addAction(a);
// l->addStretch(1);
{
oo = new QMenu(_("Primitives ..."),this);
aa=a = new QAction(QPixmap(line_xpm), _("Add line"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addLine()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add line which properties can be changed later by mouse."));
oo->addAction(a);
a = new QAction(QPixmap(arc_xpm), _("Add arc"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addArc()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add arc which properties can be changed later by mouse."));
oo->addAction(a);
a = new QAction(QPixmap(curve_xpm), _("Add curve"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addCurve()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add curve which properties can be changed later by mouse."));
oo->addAction(a);
a = new QAction(QPixmap(mark_s_xpm), _("Add rect"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addRect()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add rectangle which properties can be changed later by mouse."));
oo->addAction(a);
a = new QAction(QPixmap(mark_d_xpm), _("Add rhombus"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addRhomb()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add rhombus which properties can be changed later by mouse."));
oo->addAction(a);
a = new QAction(QPixmap(mark_o_xpm), _("Add ellipse"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addEllipse()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add ellipse which properties can be changed later by mouse."));
oo->addAction(a);
a = new QAction(QPixmap(polygon_xpm), _("Add polygon"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addPolygon()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add ellipse which properties can be changed later by mouse."));
oo->addAction(a);
a = new QAction(QPixmap(mark_a_xpm), _("Add mark"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addMark()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add marker which properties can be changed later by mouse."));
oo->addAction(a);
a = new QAction(QPixmap(text_xpm), _("Add text"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(addText()));
connect(mgl, SIGNAL(usePrimChanged(bool)), a, SLOT(setVisible(bool)));
a->setToolTip(_("Add text which properties can be changed later by mouse."));
oo->addAction(a);
QToolButton *bb = new QToolButton(this);
bb->setDefaultAction(aa); bb->setMenu(oo);
bb->setPopupMode(QToolButton::MenuButtonPopup);
t->addWidget(bb);
}
a = new QAction(QPixmap(":/png/edit-delete.png"), _("Delete selected"), this);
connect(a, SIGNAL(triggered()), this, SLOT(deleteSelected()));
a->setToolTip(_("Delete selected plot."));
o->addAction(a); popup->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/layer-visible-off.png"), _("Hide selected"), this);
connect(a, SIGNAL(triggered()), this, SLOT(hideSelected()));
a->setToolTip(_("Hide selected plots."));
o->addAction(a); popup->addAction(a); t->addAction(a);
const MainWindow *mw=findMain(this);
if(mw) t->addAction(mw->ahide);
a = new QAction(QPixmap(":/png/format-indent-more.png"), _("New command"), this);
connect(a, SIGNAL(triggered()), newCmdDlg, SLOT(show()));
a->setToolTip(_("Show dialog for new command or edit arguments of existed one."));
o->addAction(a); popup->addAction(a); t->addAction(a);
a = new QAction(QPixmap(box_xpm), _("New inplot"), this);
connect(a, SIGNAL(triggered()), subplotDlg, SLOT(show()));
a->setToolTip(_("Show dialog for new inplot and put it into the script."));
o->addAction(a); popup->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/object-order-lower.png"), _("Move plot up"), this);
connect(a, SIGNAL(triggered()), this, SLOT(movePlotUp()));
a->setToolTip(_("Move selected plot up to previous subplot."));
o->addAction(a); popup->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/object-order-raise.png"), _("Move plot down"), this);
connect(a, SIGNAL(triggered()), this, SLOT(movePlotDown()));
a->setToolTip(_("Move selected plot down to next subplot."));
o->addAction(a); popup->addAction(a); t->addAction(a);
o->addMenu(oo); //t->addSeparator();
tet = new QSpinBox(this); tet->setWrapping(true);
t->addWidget(tet); tet->setRange(-180, 180); tet->setSingleStep(10);
connect(tet, SIGNAL(valueChanged(int)), mgl, SLOT(setTet(int)));
connect(mgl, SIGNAL(tetChanged(int)), tet, SLOT(setValue(int)));
tet->setToolTip(_("Set value of \\theta angle.\nYou can use keys (Shift+Meta+Up or Shift+Meta+Down)."));
phi = new QSpinBox(this); phi->setWrapping(true);
t->addWidget(phi); phi->setRange(-180, 180); phi->setSingleStep(10);
connect(phi, SIGNAL(valueChanged(int)), mgl, SLOT(setPhi(int)));
connect(mgl, SIGNAL(phiChanged(int)), phi, SLOT(setValue(int)));
phi->setToolTip(_("Set value of \\phi angle.\nYou can use keys (Shift+Meta+Left or Shift+Meta+Right)."));
oo = new QMenu(_("Export as 2D ..."),this);
oo->addAction(_("PNG"), mgl, SLOT(exportPNG()),Qt::ALT|Qt::Key_P);
oo->addAction(_("solid PNG"), mgl, SLOT(exportPNGs()),Qt::ALT|Qt::Key_F);
oo->addAction(_("JPEG"), mgl, SLOT(exportJPG()),Qt::ALT|Qt::Key_J);
oo->addAction(_("bitmap EPS"), mgl, SLOT(exportBPS()));
oo->addAction(_("vector EPS"), mgl, SLOT(exportEPS()),Qt::ALT|Qt::Key_E);
oo->addAction(_("SVG"), mgl, SLOT(exportSVG()),Qt::ALT|Qt::Key_S);
oo->addAction(_("LaTeX"), mgl, SLOT(exportTEX()),Qt::ALT|Qt::Key_L);
o->addMenu(oo); popup->addMenu(oo);
oo = new QMenu(_("Export as 3D ..."),this);
oo->addAction(_("MGLD"), mgl, SLOT(exportMGLD()),Qt::ALT|Qt::Key_M);
oo->addAction(_("PRC"), mgl, SLOT(exportPRC()),Qt::ALT|Qt::Key_D);
oo->addAction(_("OBJ"), mgl, SLOT(exportOBJ()),Qt::ALT|Qt::Key_O);
oo->addAction(_("STL"), mgl, SLOT(exportSTL()));
oo->addAction(_("XYZ"), mgl, SLOT(exportXYZ()));
// oo->addAction(_("X3D"), QMGL, SLOT(exportX3D()),Qt::ALT|Qt::Key_X); // TODO: Add later
o->addMenu(oo); popup->addMenu(oo);
}
//-----------------------------------------------------------------------------
void PlotPanel::toolLeft(QBoxLayout *h)
{
QAction *a;
QMenu *o=menu, *oo;
QToolBar *t = new QToolBar(this); h->addWidget(t); t->setMovable(false);
t->setAllowedAreas(Qt::LeftToolBarArea); t->setOrientation(Qt::Vertical);
// zooming menu
oo = o->addMenu(_("Zoom/move"));
a = new QAction(QPixmap(":/png/arrow-left.png"), _("Move left"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(shiftLeft()));
a->setShortcut(Qt::ALT|Qt::Key_Left);
a->setToolTip(_("Move graphics left by 1/3 of its width."));
oo->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/arrow-up.png"), _("Move up"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(shiftUp()));
a->setShortcut(Qt::ALT|Qt::Key_Up);
a->setToolTip(_("Move graphics up by 1/3 of its height."));
oo->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/zoom-in.png"), _("Zoom in"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(zoomIn()));
a->setShortcut(Qt::ALT|Qt::Key_Equal);
a->setToolTip(_("Zoom in graphics."));
oo->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/zoom-out.png"), _("Zoom out"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(zoomOut()));
a->setShortcut(Qt::ALT|Qt::Key_Minus);
a->setToolTip(_("Zoom out graphics."));
oo->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/arrow-down.png"), _("Move down"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(shiftDown()));
a->setShortcut(Qt::ALT|Qt::Key_Down);
a->setToolTip(_("Move graphics down 1/3 of its height."));
oo->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/arrow-right.png"), _("Move right"), this);
connect(a, SIGNAL(triggered()), mgl, SLOT(shiftRight()));
a->setShortcut(Qt::ALT|Qt::Key_Right);
a->setToolTip(_("Move graphics right by 1/3 of its width."));
oo->addAction(a); t->addAction(a);
// rotate menu
oo = o->addMenu(_("Rotate"));
a = new QAction(QPixmap(":/png/object-rotate-up.png"), _("Rotate up"), this);
a->setShortcut(Qt::SHIFT|Qt::META|Qt::Key_Up);
connect(a, SIGNAL(triggered()), tet, SLOT(stepUp())); oo->addAction(a);
a->setToolTip(_("Increase \\theta angle by 10 degrees."));
a = new QAction(QPixmap(":/png/object-rotate-down.png"), _("Rotate down"), this);
a->setShortcut(Qt::SHIFT|Qt::META|Qt::Key_Down);
connect(a, SIGNAL(triggered()), tet, SLOT(stepDown())); oo->addAction(a);
a->setToolTip(_("Decrease \\theta angle by 10 degrees."));
a = new QAction(QPixmap(":/png/object-rotate-left.png"), _("Rotate left"), this);
a->setShortcut(Qt::SHIFT|Qt::META|Qt::Key_Right);
connect(a, SIGNAL(triggered()), phi, SLOT(stepUp())); oo->addAction(a);
a->setToolTip(_("Increase \\phi angle by 10 degrees."));
a = new QAction(QPixmap(":/png/object-rotate-right.png"), _("Rotate right"), this);
a->setShortcut(Qt::SHIFT|Qt::META|Qt::Key_Left);
connect(a, SIGNAL(triggered()), phi, SLOT(stepDown())); oo->addAction(a);
a->setToolTip(_("Decrease \\phi angle by 10 degrees."));
// animation menu
oo = o->addMenu(_("Animation"));
a = new QAction(QPixmap(":/png/media-seek-forward.png"), _("Next slide"), this);
connect(a, SIGNAL(triggered()), this, SLOT(nextSlide()));
a->setShortcut(Qt::CTRL|Qt::Key_Period);
a->setToolTip(_("Show next slide (Ctrl+.)."));
oo->addAction(a); t->addAction(a);
a = new QAction(QPixmap(":/png/media-playback-start.png"), _("Slideshow"), this);
a->setCheckable(true);
connect(a, SIGNAL(toggled(bool)), this, SLOT(animStart(bool)));
connect(this, SIGNAL(animSwitch(bool)),a,SLOT(setChecked(bool)));
a->setToolTip(_("Run slideshow (Ctrl+F5). If no parameter specified\nthen the dialog with slideshow options will appear."));
a->setShortcut(Qt::CTRL|Qt::Key_F5); oo->addAction(a); t->addAction(a);
oo->addAction(_("Setup show"), this, SLOT(animSetup()), Qt::CTRL|Qt::Key_W);
a = new QAction(QPixmap(":/png/media-seek-backward.png"), _("Prev slide"), this);
connect(a, SIGNAL(triggered()), this, SLOT(prevSlide()));
a->setShortcut(Qt::CTRL|Qt::Key_Comma);
a->setToolTip(_("Show previous slide (Ctrl+,)."));
oo->addAction(a); t->addAction(a);
}
//-----------------------------------------------------------------------------
QString PlotPanel::getFit() { return QString(mgl_get_fit(mgl->getGraph())); }
//-----------------------------------------------------------------------------
void PlotPanel::deleteSelected()
{
if(curPos>=0)
{
textMGL->moveCursor(QTextCursor::Start);
for(int i=0;i<curPos;i++) textMGL->moveCursor(QTextCursor::NextBlock);
QTextCursor tc= textMGL->textCursor();
tc.select(QTextCursor::LineUnderCursor);
tc.removeSelectedText();
tc.deleteChar();
curPos = -1; execute();
}
else emit setStatus("No selection.");
}
//-----------------------------------------------------------------------------
void PlotPanel::hideSelected()
{
if(curPos>=0)
{
textMGL->moveCursor(QTextCursor::Start);
for(int i=0;i<curPos;i++) textMGL->moveCursor(QTextCursor::NextBlock);
textMGL->insertPlainText("#h ");
curPos = -1; execute();
}
else emit setStatus("No selection.");
}
//-----------------------------------------------------------------------------
void PlotPanel::putCmd(const QString &cmd)
{
textMGL->moveCursor(QTextCursor::Start);
if(curPos>=0) for(int i=0;i<curPos;i++)
textMGL->moveCursor(QTextCursor::NextBlock);
textMGL->insertPlainText(cmd+"\n");
curPos = -1; execute();
}
//-----------------------------------------------------------------------------
void PlotPanel::insCmd(const QString &cmd)
{
textMGL->moveCursor(QTextCursor::EndOfBlock);
textMGL->insertPlainText("\n"+cmd);
curPos = -1; execute();
}
//-----------------------------------------------------------------------------
void PlotPanel::movePlotUp()
{
if(curPos>0)
{
QTextCursor tc = textMGL->textCursor();
tc.movePosition(QTextCursor::Start);
tc.movePosition(QTextCursor::NextBlock,QTextCursor::MoveAnchor,curPos);
tc.select(QTextCursor::BlockUnderCursor);
QString s = tc.selectedText();
tc.deleteChar();
bool ins=true;
while(tc.movePosition(QTextCursor::PreviousBlock))
{
QString q = tc.block().text();
if(q.startsWith("subplot ") || q.startsWith("inplot ") || q.startsWith("multiplot ") || q.startsWith("gridplot ") || q.startsWith("columnplot ") || q.startsWith("stickplot "))
{
tc.movePosition(QTextCursor::EndOfBlock);
tc.insertText(s); ins=false; break;
}
}
if(ins)
{
tc.movePosition(QTextCursor::Start); tc.insertText(s+"\n");
tc.movePosition(QTextCursor::Start); tc.deleteChar();
}
curPos = tc.block().blockNumber(); execute();
}
else if(curPos<0) emit setStatus("No selection.");
}
//-----------------------------------------------------------------------------
void PlotPanel::movePlotDown()
{
if(curPos>=0)
{
QTextCursor tc = textMGL->textCursor();
tc.movePosition(QTextCursor::Start);
tc.movePosition(QTextCursor::NextBlock,QTextCursor::MoveAnchor,curPos);
tc.select(QTextCursor::BlockUnderCursor);
QString s = tc.selectedText();
if(curPos==0) s = "\n"+s;
tc.deleteChar();
bool ins=true;
while(tc.movePosition(QTextCursor::NextBlock))
{
QString q = tc.block().text();
if(q.startsWith("subplot ") || q.startsWith("inplot ") || q.startsWith("multiplot ") || q.startsWith("gridplot ") || q.startsWith("columnplot ") || q.startsWith("stickplot "))
{
tc.movePosition(QTextCursor::EndOfBlock);
tc.insertText(s); ins=false; break;
}
}
if(ins) { tc.movePosition(QTextCursor::End); tc.insertText(s); }
curPos = tc.block().blockNumber(); execute();
}
else emit setStatus("No selection.");
}
//-----------------------------------------------------------------------------
|