coolButton------JavaScript

一.coolButton.js

document.onmouseover = doOver;
document.onmouseout  = doOut;
document.onmousedown = doDown;
document.onmouseup   = doUp;
document.onclick   = doClick;
function doOver() {
 var toEl = getReal(window.event.toElement, "className", "coolButton");
 var fromEl = getReal(window.event.fromElement, "className", "coolButton");
 if (toEl == fromEl) return;
 var el = toEl;
 
 var cDisabled = el.cDisabled;

 cDisabled = (cDisabled != null);
 
 if (el.className == "coolButton")
  el.onselectstart = new Function("return false");
 
 if ((el.className == "coolButton") && !cDisabled) {
  if(el.havearrow==1){
  makeRaised(el);
  makeRaised(eval(el.aname));
  }
  else{makeRaised(el);}

 }
}

function doOut() {
 var toEl = getReal(window.event.toElement, "className", "coolButton");
 var fromEl = getReal(window.event.fromElement, "className", "coolButton");
 if (toEl == fromEl) return;
 var el = fromEl;

 var cDisabled = el.cDisabled;
 cDisabled = (cDisabled != null);

 var cToggle = el.cToggle;
 toggle_disabled = (cToggle != null);

 if (cToggle && el.value) {
  
  makePressed(el);
  

 }
 else if ((el.className == "coolButton") && !cDisabled) {
  if(el.havearrow==1){
  makeFlat(el);
  makeFlat(eval(el.aname));
  }
  else{makeFlat(el);}
  makeFlat(el);
  
 }

}

function doDown() {
 el = getReal(window.event.srcElement, "className", "coolButton");
 
 var cDisabled = el.cDisabled;
 cDisabled = (cDisabled != null); // If CDISABLED atribute is present
 
 if ((el.className == "coolButton") && !cDisabled) {
  makePressed(el)
  
 }
}

function doClick() {
 el = getReal(window.event.srcElement, "className", "coolButton");
 
 var cDisabled = el.cDisabled;
 cDisabled = (cDisabled != null);
 
 if ((el.className == "coolButton") && !cDisabled) {
  makePressed(el)
  
 }
}

function doUp() {
 el = getReal(window.event.srcElement, "className", "coolButton");
 
 var cDisabled = el.cDisabled;
 cDisabled = (cDisabled != null);
 
 if ((el.className == "coolButton") && !cDisabled) {
  makeRaised(el);
 }
}


function getReal(el, type, value) {
 temp = el;
 while ((temp != null) && (temp.tagName != "BODY")) {
  if (eval("temp." + type) == value) {
   el = temp;
   return el;
  }
  temp = temp.parentElement;
 }
 return el;
}

 

function disable(el) {

 if (document.readyState != "complete") {
  window.setTimeout("disable(" + el.id + ")", 100);
  return;
 }
 
 var cDisabled = el.cDisabled;
 
 cDisabled = (cDisabled != null);
 if (!cDisabled) {
  el.cDisabled = true;
  
  if (document.getElementsByTagName) { 
   el.innerHTML = "<span style='background: buttonshadow; filter: chroma(color=red) dropshadow(color=buttonhighlight, offx=1, offy=1); width: 100%; height: 100%; text-align: center;'>" +
       "<span style='filter: mask(color=red); width: 100%; height: 100%; text-align: center;'>" +
       el.innerHTML +
       "</span>" +
       "</span>";
  }
  else { // IE4
   el.innerHTML = '<span style="background: buttonshadow; width: 100%; height: 100%; text-align: center;">' +
       '<span style="filter:Mask(Color=buttonface) DropShadow(Color=buttonhighlight, OffX=1, OffY=1, Positive=0); height: 100%; width: 100%%; text-align: center;">' +
       el.innerHTML +
       '</span>' +
       '</span>';
  }
  
  

  if (el.onclick != null) {
   el.cDisabled_onclick = el.onclick;
   el.onclick = null;
  }
 }
}

function enable(el) {
 var cDisabled = el.cDisabled;
 
 cDisabled = (cDisabled != null);
 
 if (cDisabled) {
  el.cDisabled = null;
  el.innerHTML = el.children[0].children[0].innerHTML;

  if (el.cDisabled_onclick != null) {
   el.onclick = el.cDisabled_onclick;
   el.cDisabled_onclick = null;
  }
 }
}

 

 

function makeFlat(el) {
 with (el.style) {
  background = "";
  border = "1px solid buttonface";
  padding      = "1px";
 }
}

function makeRaised(el) {
 with (el.style) {
  borderLeft   = "1px solid buttonhighlight";
  borderRight  = "1px solid buttonshadow";
  borderTop    = "1px solid buttonhighlight";
  borderBottom = "1px solid buttonshadow";
  padding      = "1px";
 }
}

function makePressed(el) {
 with (el.style) {
  borderLeft   = "1px solid buttonshadow";
  borderRight  = "1px solid buttonhighlight";
  borderTop    = "1px solid buttonshadow";
  borderBottom = "1px solid buttonhighlight";
  paddingTop    = "2px";
  paddingLeft   = "2px";
  paddingBottom = "0px";
  paddingRight  = "0px";
 }
}

 

document.write("<style>");
document.write(".coolBar {background: buttonface;border-top: 1px solid buttonhighlight; border-left: 1px solid buttonhighlight; border-bottom: 1px solid buttonshadow; border-right: 1px solid buttonshadow; padding: 2px; font: menu;}");
document.write(".coolButton {border: 1px solid buttonface; padding: 1px; text-align: center; cursor: default;font-size:12px;font-family:ms shell dlg;line-height:20px}");
document.write(".coolButton IMG {filter:;}");
document.write("</style>");

 二.coolbutton.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="javascript" src="coolbuttons.js"></script>
</HEAD>

<BODY>
<table bgcolor=buttonface>
   <tr>
      <td class="coolButton" nowrap height=10 width=100>&nbsp;&nbsp;coolbutton&nbsp;&nbsp;</td>
   <td class="coolButton" nowrap height=10 width=100>&nbsp;&nbsp;url&nbsp;&nbsp;</td>
   </tr>
</table>
</BODY>
</HTML>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个使用QT编写的简单的智能饮水机程序,包含温度控制、水位控制和状态显示功能。 首先,在QT Creator中创建一个新的Qt Widgets应用程序项目。然后,在设计模式下,使用拖放的方式创建控件并设置其属性和布局。在本例中,我们使用了以下控件: - QLabel:显示文本标签。 - QProgressBar:显示水位和温度进度条。 - QSpinBox:设置加热和制冷的温度。 - QPushButton:控制加热、制冷和出水。 - QLCDNumber:显示当前温度。 然后,在mainwindow.cpp文件中编写代码来实现饮水机的逻辑功能。以下是完整的代码: ```c++ #include "mainwindow.h" #include "ui_mainwindow.h" #include <QMessageBox> #include <QTimer> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); // 初始化状态为待机 status = "待机"; ui->statusLabel->setText(status); // 初始化温度为室温 currentTemp = 25; ui->tempDisplay->display(currentTemp); // 初始化水位为满 currentWaterLevel = 100; ui->waterLevel->setValue(currentWaterLevel); // 创建定时器,定期检查温度和水位 QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(checkTempAndWaterLevel())); timer->start(1000); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_heatButton_clicked() { // 开始加热 if (status == "待机" || status == "制冷中") { status = "加热中"; ui->statusLabel->setText(status); } else { QMessageBox::warning(this, "警告", "当前状态无法加热!"); return; } // 获取目标温度 targetTemp = ui->heatTemp->value(); // 创建定时器,模拟加热过程 heatTimer = new QTimer(this); connect(heatTimer, SIGNAL(timeout()), this, SLOT(heatWater())); heatTimer->start(1000); } void MainWindow::on_coolButton_clicked() { // 开始制冷 if (status == "待机" || status == "加热中") { status = "制冷中"; ui->statusLabel->setText(status); } else { QMessageBox::warning(this, "警告", "当前状态无法制冷!"); return; } // 获取目标温度 targetTemp = ui->coolTemp->value(); // 创建定时器,模拟制冷过程 coolTimer = new QTimer(this); connect(coolTimer, SIGNAL(timeout()), this, SLOT(coolWater())); coolTimer->start(1000); } void MainWindow::on_waterButton_clicked() { // 开始出水 if (status == "待机") { QMessageBox::warning(this, "警告", "当前状态无法出水!"); return; } status = "出水中"; ui->statusLabel->setText(status); // 创建定时器,模拟出水过程 waterTimer = new QTimer(this); connect(waterTimer, SIGNAL(timeout()), this, SLOT(pourWater())); waterTimer->start(1000); } void MainWindow::heatWater() { // 加热过程中,每秒增加1度温度 currentTemp += 1; ui->tempDisplay->display(currentTemp); if (currentTemp >= targetTemp) { heatTimer->stop(); status = "待机"; ui->statusLabel->setText(status); } } void MainWindow::coolWater() { // 制冷过程中,每秒减少1度温度 currentTemp -= 1; ui->tempDisplay->display(currentTemp); if (currentTemp <= targetTemp) { coolTimer->stop(); status = "待机"; ui->statusLabel->setText(status); } } void MainWindow::pourWater() { // 出水过程中,每秒流失10%的水位 currentWaterLevel -= 10; ui->waterLevel->setValue(currentWaterLevel); if (currentWaterLevel <= 0) { waterTimer->stop(); status = "待机"; ui->statusLabel->setText(status); currentWaterLevel = 0; ui->waterLevel->setValue(currentWaterLevel); } } void MainWindow::checkTempAndWaterLevel() { // 检查温度和水位,发出警告 if (currentTemp >= 90) { QMessageBox::warning(this, "警告", "水温过高!"); } if (currentWaterLevel <= 20) { QMessageBox::warning(this, "警告", "水位过低!"); } } ``` 在这个代码中,我们使用了四个定时器来模拟加热、制冷、出水和检查温度和水位的过程。每个定时器触发后都会调用对应的槽函数来更新界面和状态。需要注意的是,加热和制冷过程中需要记录目标温度,以便判断何时停止定时器。 希望这个完整的代码可以帮助您了解如何使用QT编写智能饮水机程序。如果您有任何问题或需要更多的帮助,请随时告诉我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值