Exemple #1
0
BarGraph::BarGraph(int nodeId, QWidget *parent) :
    QDeclarativeItem(NULL)
    , m_customPlot(new QCustomPlot(parent))
    , m_proxy(new QGraphicsProxyWidget(this))
    , m_refreshButton(new QPushButton("&Stop refresh", parent))
    , m_colorId(0)
    , m_active(true)
{
    QWidget *widget;
    QVBoxLayout *vLayout;
    QHBoxLayout *hLayout;

    // Important, otherwise the paint method is never called
    setFlag(QGraphicsItem::ItemHasNoContents, false);
    setNodeId(nodeId);

    widget = new QWidget(parent);
    widget->setStyleSheet("background-color:#c2bbb8;");

    hLayout = new QHBoxLayout(parent);
    hLayout->addItem(new QSpacerItem(150, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
    hLayout->addWidget(m_refreshButton);

    vLayout = new QVBoxLayout(parent);
    vLayout->addWidget(m_customPlot);
    vLayout->addItem(hLayout);

    widget->setLayout(vLayout);
    m_proxy->setWidget(widget);

    connect(m_refreshButton, SIGNAL(clicked()), SLOT(toggleTimer()));

    m_customPlot->yAxis->setSubGrid(true);
    m_customPlot->yAxis->setRange(0, 100);

    m_customPlot->xAxis->setGrid(false);
    m_customPlot->xAxis->setSubTickCount(0);
    m_customPlot->xAxis->setTickLength(0, 10);
    m_customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    m_customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
    m_customPlot->xAxis->setAutoTickStep(false);
    m_customPlot->xAxis->setTickStep(10);
    m_customPlot->setupFullAxesBox();

    m_customPlot->legend->setVisible(true);
    m_customPlot->legend->setPositionStyle(QCPLegend::psTopLeft);
    m_customPlot->legend->setBrush(QBrush(QColor(255, 255, 255, 200)));
}
/*Configures timer 1 with the proper values.*/
void StepperControl::timerSetup(){
	cli(); //Stop interrupts

	//Set timer1 interrupts
	TCCR1A = 0; // Set entire TCCR1A register to 0
	TCCR1B = 0; // Same for TCCR1B
	TCNT1  = 0; // Initialize counter value to 0
	//Set compare match register to the given idle time.
	OCR1A = idleTime; //(must be <65536)
	//Turn on CTC mode
	TCCR1B |= (1 << WGM12);
	//Set CS10 and CS11 bits for 64 prescaler
	//TCCR1B |= (1 << CS11) | (1 << CS10); //Using toggleTimer(1) instead.
	toggleTimer(1);
	//Enable timer compare interrupt
	//TIMSK1 |= (1 << OCIE1A);

	sei();//allow interrupts
}
Exemple #3
0
static gboolean onKeyPressed(GtkWidget *widget, GdkEventKey *ev,
		gpointer data)
{
	/* Unused parameters. */
	(void)data;

	guint key = ev->keyval;
	gchar *msg = NULL;

	/* When inside the note pad, don't do anything here. */
	if (isInsideNotePad)
		return FALSE;

	/* Jump command?
	 *
	 * Note: This works as long as the values of GDK keysyms satisfy:
	 *   1)  GDK_0 < GDK_1 < GDK_2 < ... < GDK_9
	 *   2)  All of them must be >= 0.
	 */
	key -= GDK_0;
	if (key <= 9)
	{
		/* The initial value is -1, so we have to reset this on the
		 * first key stroke. */
		if (target_page < 0)
			target_page = 0;

		/* Do a "decimal left shift" and add the given value. */
		target_page *= 10;
		target_page += (int)key;

		/* Catch overflow and announce what would happen. */
		if (target_page < 0)
		{
			target_page = -1;
			setStatusText_strdup("Invalid page.");
		}
		else
		{
			msg = g_strdup_printf("Jump to page: %d", target_page);
			setStatusText_strdup(msg);
			g_free(msg);
		}

		return FALSE;
	}

	gboolean changed = TRUE;
	saveCurrentNote();

	switch (ev->keyval)
	{
		case GDK_Right:
		case GDK_Down:
		case GDK_Page_Down:
		case GDK_space:
			nextSlide();
			break;

		case GDK_Left:
		case GDK_Up:
		case GDK_Page_Up:
			prevSlide();
			break;

		case GDK_F5:
			/* Switch to fullscreen (if needed) and start the timer
			 * (unless it's already running). */
			if (!isFullScreen)
				toggleFullScreen();
			if (timerMode != 1)
				toggleTimer();
			break;

		case GDK_F6:
			/* this shall trigger a hard refresh, so empty the cache. */
			clearCache();
			break;

		case GDK_w:
			runpref.fit_mode = FIT_WIDTH;
			break;

		case GDK_h:
			runpref.fit_mode = FIT_HEIGHT;
			break;

		case GDK_p:
			runpref.fit_mode = FIT_PAGE;
			break;

		case GDK_l:
			current_fixate();
			break;

		case GDK_L:
			current_release(FALSE);
			break;

		case GDK_J:
			current_release(TRUE);
			break;

		case GDK_f:
			toggleFullScreen();
			break;

		case GDK_s:
			toggleTimer();
			changed = FALSE;
			break;

		case GDK_c:
			toggleCurserVisibility();
			break;

		case GDK_r:
			resetTimer();
			changed = FALSE;
			break;

		case GDK_Escape:
		case GDK_q:
			if (prefs.q_exits_fullscreen && isFullScreen)
			{
				toggleFullScreen();
				if (prefs.stop_timer_on_fs)
				{
					toggleTimer();
				}
			}
			else
			{
				changed = FALSE;
				onQuit(NULL, NULL, NULL);
			}
			break;

		case GDK_i:
			/* This must not work when we're on the beamer window. */
			if (widget != win_beamer)
				setEditingState(TRUE);

			changed = FALSE;
			break;

		case GDK_Return:
			if (executeJump() == 0)
				nextSlide();
			break;

		case GDK_G:
			executeJump();
			break;

		case GDK_period:
		case GDK_b:
			toggleBlankBeamer();
			changed = FALSE;
			break;

		default:
			changed = FALSE;
	}

	if (changed == TRUE)
	{
		refreshPorts();
	}

	return TRUE;
}
/**
 * @short Initialize
 * @author Rene Schmidt <*****@*****.**>
 * @version 0.1
 */
KLAidWidget::KLAidWidget(QWidget* parent, const char* name, WFlags fl)
        : KLAidWidgetBase(parent,name,fl)
{
  this->setCaption(i18n("K Learning Aid %1").arg(VER));

  cfgOkay = FALSE;
  
  oldRepVal = 1;
  
  // Center window
  QDesktopWidget *d = QApplication::desktop();
  int dW = d->width();      int dH = d->height();
  int wW = this->width();   int wH = this->height();
  this->setGeometry((dW-wW)/2, (dH-wH)/2, wW, wH);
  
  // Create tray icon
  tray = new KSystemTray(this, "TimerTray");
  tray->setPixmap(SmallIcon("ktimer"));
  tray->show();

  QToolTip::add(tray, i18n("K Learning Aid %1").arg(VER));
  
  // Create logic backend
  aut = new KLAid(this);
  aut->desktopWidth = d->width();
  aut->setCentralWidget(tray);
  
  QObject::connect(aut, SIGNAL(loopExpired()), this, SLOT(reportExpired()));
  QObject::connect(aut, SIGNAL(popNow( QString&, QString&, uint&)),
                    this, SLOT(showPopUp(QString&, QString&, uint&)));

  // Add some tray menu items
  KPopupMenu * TrayMenu = tray->contextMenu(); 

  enPopAction = new KToggleAction(  i18n("&Enable PopUps"),
                                    0, 
                                    this, 
                                    SLOT(toggleTimer()), 
                                    parentWidget(), 
                                    TOGGLE_ITEM);

  KAction * AboutAction = new KAction(  i18n("&About"), 
                                        0, 
                                        this, 
                                        SLOT(about()), 
                                        parentWidget(), 
                                        ABOUT_ITEM);
      
  TrayMenu->removeItemAt(0);
  TrayMenu->insertTitle(SmallIcon("ktimer"), QString("KLAid"), 0, 0);
  
  enPopAction->plug(TrayMenu, 1);
  enPopAction->setEnabled(FALSE);
  
  AboutAction->plug(TrayMenu, 2);

  connect(popUpInterval, SIGNAL(valueChanged(const QString&)), this, SLOT(sanitizeMinStay()));
  connect(urlLine, SIGNAL(urlSelected(const QString&)), this, SLOT(enableOKButton()));
  connect(minStay, SIGNAL(valueChanged(const QString&)), this, SLOT(sanitizeMinStay()));
  connect(pIntvalUnit, SIGNAL(activated(const QString&)), this, SLOT(sanitizeMinStay()));
  connect(overlapPops, SIGNAL(stateChanged(int)), this, SLOT(sanitizeMinStay()));
  connect(rndSeqBox, SIGNAL(stateChanged(int)), this, SLOT(turnOffUniq()));
  connect(repModeBox, SIGNAL(activated(const QString&)), this, SLOT(changeRepMode()));
  connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
  connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
//  connect(defaultsButton, SIGNAL(clicked()), this, SLOT(resetConfig()));

  // Set default fonts for popups
  fntCaption = new QFont();
  fntCaption->setBold(TRUE);
  kFontRequester1->setFont(*fntCaption);
  fntBody = new QFont();
  kFontRequester2->setFont(*fntBody);

  // Set default fonts for popups
  tmpFgColor = new QColor(this->foregroundColor());
  tmpBgColor = new QColor(this->backgroundColor());

  fgCol->setColor(this->foregroundColor());
  bgCol->setColor(this->backgroundColor());

  this->_readConfig();
  this->show();
}