TextFormatButtons::TextFormatButtons(QTextEdit * textEdit, Buttons buttons, QWidget * parent)
: QWidget(parent),
connectedTextEdit(textEdit),
d_buttons(buttons)
{
	QHBoxLayout * layout = new QHBoxLayout(this);
	layout->setMargin(0);
	layout->setSpacing(0);

	QFont font = this->font();
	font.setPointSize(14);

	if (buttons == Legend){
		buttonCurve = new QPushButton( QPixmap(lineSymbol_xpm), QString());
		buttonCurve->setMaximumWidth(40);
		buttonCurve->setMinimumHeight(35);
		buttonCurve->setFont(font);
		layout->addWidget(buttonCurve);
		connect( buttonCurve, SIGNAL(clicked()), this, SLOT(addCurve()) );
	}

	buttonSubscript = new QPushButton(QPixmap(index_xpm), QString());
	buttonSubscript->setMaximumWidth(40);
	buttonSubscript->setMinimumHeight(35);
	buttonSubscript->setFont(font);
	layout->addWidget(buttonSubscript);
	connect( buttonSubscript, SIGNAL(clicked()), this, SLOT(addSubscript()) );

	buttonSuperscript = new QPushButton(QPixmap(exp_xpm), QString());
	buttonSuperscript->setMaximumWidth(40);
	buttonSuperscript->setMinimumHeight(35);
	buttonSuperscript->setFont(font);
	layout->addWidget(buttonSuperscript);
	connect( buttonSuperscript, SIGNAL(clicked()), this, SLOT(addSuperscript()));

	if (buttons != Equation){
		buttonLowerGreek = new QPushButton(QString(QChar(0x3B1)));
		buttonLowerGreek->setFont(font);
		buttonLowerGreek->setMaximumWidth(40);
		layout->addWidget(buttonLowerGreek);
		connect( buttonLowerGreek, SIGNAL(clicked()), this, SLOT(showLowerGreek()));

		buttonUpperGreek = new QPushButton(QString(QChar(0x393)));
		buttonUpperGreek->setFont(font);
		buttonUpperGreek->setMaximumWidth(40);
		layout->addWidget(buttonUpperGreek);
		connect( buttonUpperGreek, SIGNAL(clicked()), this, SLOT(showUpperGreek()));

		buttonMathSymbols = new QPushButton(QString(QChar(0x222B)));
		buttonMathSymbols->setFont(font);
		buttonMathSymbols->setMaximumWidth(40);
		layout->addWidget(buttonMathSymbols);
		connect( buttonMathSymbols, SIGNAL(clicked()), this, SLOT(showMathSymbols()));

		buttonArrowSymbols = new QPushButton(QString(QChar(0x2192)));
		buttonArrowSymbols->setFont(font);
		buttonArrowSymbols->setMaximumWidth(40);
		layout->addWidget(buttonArrowSymbols);
		connect( buttonArrowSymbols, SIGNAL(clicked()), this, SLOT(showArrowSymbols()));
	}

	if (buttons != Plot3D && buttons != Equation){
		font = this->font();
		font.setBold(true);
		font.setPointSize(14);

		buttonBold = new QPushButton(tr("B","Button bold"));
		buttonBold->setFont(font);
		buttonBold->setMaximumWidth(40);
		layout->addWidget(buttonBold);
		connect( buttonBold, SIGNAL(clicked()), this, SLOT(addBold()));

		font = this->font();
		font.setItalic(true);
		font.setPointSize(14);

		buttonItalics = new QPushButton(tr("It","Button italics"));
		buttonItalics->setFont(font);
		buttonItalics->setMaximumWidth(40);
		layout->addWidget(buttonItalics);
		connect( buttonItalics, SIGNAL(clicked()), this, SLOT(addItalics()));

		font = this->font();
		font.setUnderline(true);
		font.setPointSize(14);

		buttonUnderline = new QPushButton(tr("U","Button underline"));
		buttonUnderline->setFont(font);
		buttonUnderline->setMaximumWidth(40);
		layout->addWidget(buttonUnderline);
   		layout->addStretch();
		connect( buttonUnderline, SIGNAL(clicked()), this, SLOT(addUnderline()));
	}

	if (buttons == Equation){
		buttonFraction = new QPushButton(QPixmap(fraction_xpm), QString());
		buttonFraction->setMaximumWidth(40);
		buttonFraction->setMinimumHeight(35);
		buttonFraction->setFont(font);
		layout->addWidget(buttonFraction);
		connect(buttonFraction, SIGNAL(clicked()), this, SLOT(addFraction()));

		buttonSquareRoot = new QPushButton(QPixmap(square_root_xpm), QString());
		buttonSquareRoot->setMaximumWidth(40);
		buttonSquareRoot->setMinimumHeight(35);
		buttonSquareRoot->setFont(font);
		layout->addWidget(buttonSquareRoot);
		connect(buttonSquareRoot, SIGNAL(clicked()), this, SLOT(addSquareRoot()));
		layout->addStretch();
	}
}
Example #2
0
void TextFormatButtons::init(Buttons buttons)
{
  QHBoxLayout *layout = (QHBoxLayout*)this->layout();
  QLayoutItem *child;
  while ((child = layout->takeAt(0)) != 0){
    if (child->widget())
      delete child->widget();
  }

  QFont font = QFont();
  int btnSize = 32;
#ifdef Q_OS_MAC
  btnSize = 38;
#endif
  if (buttons == Legend || buttons == TexLegend){
    QPushButton *buttonCurve = new QPushButton( QPixmap(":/lineSymbol.png"), QString());
    buttonCurve->setFixedWidth(btnSize);
    buttonCurve->setFixedHeight(btnSize);
    buttonCurve->setFont(font);
    layout->addWidget(buttonCurve);
    connect( buttonCurve, SIGNAL(clicked()), this, SLOT(addCurve()) );
  }

  QPushButton *buttonSubscript = new QPushButton(QPixmap(":/index.png"), QString());
  buttonSubscript->setFixedWidth(btnSize);
  buttonSubscript->setFixedHeight(btnSize);
  buttonSubscript->setFont(font);
  layout->addWidget(buttonSubscript);
  connect( buttonSubscript, SIGNAL(clicked()), this, SLOT(addSubscript()) );

  QPushButton *buttonSuperscript = new QPushButton(QPixmap(":/exp.png"), QString());
  buttonSuperscript->setFixedWidth(btnSize);
  buttonSuperscript->setFixedHeight(btnSize);
  buttonSuperscript->setFont(font);
  layout->addWidget(buttonSuperscript);
  connect( buttonSuperscript, SIGNAL(clicked()), this, SLOT(addSuperscript()));

  if (buttons == Equation || buttons == TexLegend){
    QPushButton *buttonFraction = new QPushButton(QPixmap(":/fraction.png"), QString());
    buttonFraction->setFixedWidth(btnSize);
    buttonFraction->setFixedHeight(btnSize);
    buttonFraction->setFont(font);
    layout->addWidget(buttonFraction);
    connect(buttonFraction, SIGNAL(clicked()), this, SLOT(addFraction()));

    QPushButton *buttonSquareRoot = new QPushButton(QPixmap(":/square_root.png"), QString());
    buttonSquareRoot->setFixedWidth(btnSize);
    buttonSquareRoot->setFixedHeight(btnSize);
    buttonSquareRoot->setFont(font);
    layout->addWidget(buttonSquareRoot);
    connect(buttonSquareRoot, SIGNAL(clicked()), this, SLOT(addSquareRoot()));
  }

  QPushButton *buttonLowerGreek = new QPushButton(QString(QChar(0x3B1)));
  buttonLowerGreek->setFont(font);
  buttonLowerGreek->setFixedWidth(btnSize);
  buttonLowerGreek->setFixedHeight(btnSize);
  layout->addWidget(buttonLowerGreek);
  connect( buttonLowerGreek, SIGNAL(clicked()), this, SLOT(showLowerGreek()));

  QPushButton *buttonUpperGreek = new QPushButton(QString(QChar(0x393)));
  buttonUpperGreek->setFont(font);
  buttonUpperGreek->setFixedWidth(btnSize);
  buttonUpperGreek->setFixedHeight(btnSize);
  layout->addWidget(buttonUpperGreek);
  connect( buttonUpperGreek, SIGNAL(clicked()), this, SLOT(showUpperGreek()));

  QPushButton *buttonArrowSymbols = new QPushButton(QString(QChar(0x2192)));
  buttonArrowSymbols->setFont(font);
  buttonArrowSymbols->setFixedWidth(btnSize);
  buttonArrowSymbols->setFixedHeight(btnSize);
  layout->addWidget(buttonArrowSymbols);
  connect( buttonArrowSymbols, SIGNAL(clicked()), this, SLOT(showArrowSymbols()));

  QPushButton *buttonMathSymbols = new QPushButton(QString(QChar(0x222B)));
  buttonMathSymbols->setFont(font);
  buttonMathSymbols->setFixedWidth(btnSize);
  buttonMathSymbols->setFixedHeight(btnSize);
  layout->addWidget(buttonMathSymbols);
  connect( buttonMathSymbols, SIGNAL(clicked()), this, SLOT(showMathSymbols()));

  if (buttons != Plot3D && buttons != Equation && buttons != TexLegend){
    font = this->font();
    font.setBold(true);

    QPushButton *buttonBold = new QPushButton(tr("B","Button bold"));
    buttonBold->setFont(font);
    buttonBold->setFixedWidth(btnSize);
    buttonBold->setFixedHeight(btnSize);
    layout->addWidget(buttonBold);
    connect( buttonBold, SIGNAL(clicked()), this, SLOT(addBold()));

    font = this->font();
    font.setItalic(true);

    QPushButton *buttonItalics = new QPushButton(tr("It","Button italics"));
    buttonItalics->setFont(font);
    buttonItalics->setFixedWidth(btnSize);
    buttonItalics->setFixedHeight(btnSize);
    layout->addWidget(buttonItalics);
    connect( buttonItalics, SIGNAL(clicked()), this, SLOT(addItalics()));

    font = this->font();
    font.setUnderline(true);

    QPushButton *buttonUnderline = new QPushButton(tr("U","Button underline"));
    buttonUnderline->setFont(font);
    buttonUnderline->setFixedWidth(btnSize);
    buttonUnderline->setFixedHeight(btnSize);
    layout->addWidget(buttonUnderline);
    layout->addStretch();
    connect( buttonUnderline, SIGNAL(clicked()), this, SLOT(addUnderline()));
  } else
    layout->addStretch();
}